2 回答

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊
創(chuàng)建一個(gè)視圖,thanks在views.py中調(diào)用
def thanks(request):
return render(request, 'thanks.html')
現(xiàn)在,通過(guò)添加到投票應(yīng)用程序的 urls.py將/poll/thanks/URL 鏈接到模板。thankspath('thanks/', views.thanks, name='thanks')
$ mysite/polls/urls.py
from django.urls import path
from polls import views
urlpatterns = [
path('thanks/', views.thanks, name='thanks'),
]
最后在 get_name 視圖中更改以下行
return HttpResponseRedirect('/polls/thanks/')

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
改變你的主要urls.py
:
url(r'^polls/', include('polls.urls')),
在您的應(yīng)用程序中urls.py
:
url(r'^$', views.get_name, name='index'),
并且在您views.py
更改為:
if form.is_valid(): # process the data in form.cleaned_data as required # ... # redirect to a new URL: return render(request, 'thanks.html')
添加回答
舉報(bào)