Django 404 Error page not found...当前路径与上一个匹配
Django 404 Error page not found...the current path matched the last one
我是 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,)))
这行错误
Raised by: polls.views.pick
告诉你你没有得到 404 是因为没有找到匹配 URL,你得到 404 是因为你的视图函数 polls.views.pick
引发了 404。你有两行那个可以引发 404
的函数
question = get_object_or_404(Question, pk=question_id)
player = get_object_or_404(Player, pk=1)
因此在您的数据库中,您要么没有 pk=1 的问题,要么没有 pk=1 的玩家。
我是 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,)))
这行错误
Raised by: polls.views.pick
告诉你你没有得到 404 是因为没有找到匹配 URL,你得到 404 是因为你的视图函数 polls.views.pick
引发了 404。你有两行那个可以引发 404
question = get_object_or_404(Question, pk=question_id)
player = get_object_or_404(Player, pk=1)
因此在您的数据库中,您要么没有 pk=1 的问题,要么没有 pk=1 的玩家。