Python Django页面未找到(404)轮询:详细url问题
在Django教程中,它要求我们将视图调整为通用视图。发布后,我可以在index.html上点击我的问题“What's up”,但这会导致页面未找到错误。代码如下: py(用于轮询) 当我单击index.html上的链接“What's up?”时,会导致以下错误:Python Django页面未找到(404)轮询:详细url问题,python,django,Python,Django,在Django教程中,它要求我们将视图调整为通用视图。发布后,我可以在index.html上点击我的问题“What's up”,但这会导致页面未找到错误。代码如下: py(用于轮询) 当我单击index.html上的链接“What's up?”时,会导致以下错误: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/polls/%7B%25%20url%20'polls:detail'%20
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/%7B%25%20url%20'polls:detail'%20question.id%20%25
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
polls/ [name='index']
polls/ <int:pk>/ [name='detail']
polls/ <int:pk>/results/ [name='results']
polls/ <int:question_id>/vote/ [name='vote']
admin/
The current path, polls/{% url 'polls:detail' question.id %, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
未找到页面(404)
请求方法:获取
请求URL:http://127.0.0.1:8000/polls/%7B%25%20url%20'轮询:详细信息'%20问题。id%20%25
Django使用mysite.URL中定义的URLconf,按以下顺序尝试了这些URL模式:
轮询/[name='index']
轮询//[name='detail']
民意测验//results/[name='results']
投票//vote/[name='vote']
管理员/
当前路径polls/{%url'polls:detail'question.id%与这些路径中的任何一个都不匹配。
看到此错误是因为Django设置文件中的DEBUG=True。将其更改为False,Django将显示标准404页面。
我来自一个酒瓶背景,学习Django,发现它组织得很好,除了这个打嗝
我尝试过将question.id改为question.pk。此外,我还尝试过在“polls:detail”周围改引号,但也没有用。您错过了
{%url%}
标记末尾的
。应该是:
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
from django.shortcuts import render,get_object_or_404
from django.http import Http404,HttpResponseRedirect
from django.urls import reverse
from django.views import generic
# Create your views here.
#from django.http import HttpResponse
from django.template import loader
from .models import Question, Choice
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]
class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'
class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/%7B%25%20url%20'polls:detail'%20question.id%20%25
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
polls/ [name='index']
polls/ <int:pk>/ [name='detail']
polls/ <int:pk>/results/ [name='results']
polls/ <int:question_id>/vote/ [name='vote']
admin/
The current path, polls/{% url 'polls:detail' question.id %, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>