发布于 2018-09-18 15:28:01
您的url模式和href链接错误;
urlpatterns = [
path('', index, name='polls_list'),
path('<int:id>/details/', views.details, name='poll_details'),
path('<int:id>/', views.poll, name='single_poll')
]并更改投票详细信息url;
<li> <a href="{% url 'poll_details' id=question.id %}">{{question.title}} </a></li>使用该选项进行更改,然后重试。
发布于 2018-09-18 15:33:57
您在poll应用程序下的详细信息视图中有问题。
try:
question=Question.objects.all.get(id=id)
except:
raise Http404您没有有效的查询,并且在except语句中引发了404,这将导致显示404页面未找到。
下面是固定的代码:
from django.core.exceptions import ObjectDoesNotExist
def details(request,id=None):
context={}
try:
question=Question.objects.get(id=id)
except ObjectDoesNotExist:
question = "Sorry! Poll does not exits with this id"
context['question']=question
return render(request, 'polls/details.html', context)https://stackoverflow.com/questions/52380849
复制相似问题