【发布时间】:2021-08-04 21:29:33
【问题描述】:
我是 django 的新手,我正在玩自己的投票教程变体。我的应用程序运行良好,每个页面都正确加载。然后我做了一个改变;我创建然后删除了一个模型。现在,许多网址似乎都坏了。我不明白这个错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/1/pick/
Raised by: polls.views.pick
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']
polls/ <int:question_id>/tally/ [name='tally']
polls/ <int:question_id>/pick/ [name='pick']
The current path, polls/1/pick/, matched the last one.
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.
所以我不明白为什么会这样说:当前路径 polls/1/pick/ 与最后一个匹配。
还找不到页面?这是如何运作的?当应用程序之前运行良好时,可能是什么导致了这种情况?
我的 urls.py:
from django.urls import path
from . import views
app_name = 'polls'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
path('<int:question_id>/tally/', views.tally, name='tally'),
path('<int:question_id>/pick/', views.pick, name='pick'),
path('<int:pk>/video/', views.VideoView.as_view(), name='video'),
path('<int:pk>/reveal/', views.RevealView.as_view(), name='reveal'),
]
和视图片段:
def pick(request, question_id):
question = get_object_or_404(Question, pk=question_id)
player = get_object_or_404(Player, pk=1)
question.score = player.score
question.save()
return HttpResponseRedirect(reverse('polls:video', args=(question.id,)))
【问题讨论】:
标签: django http-status-code-404