Firstly, it's really important to make sure that you are following the tutorial that matches your version of Django. Here are the links for Django 2.0 and Django 1.11.
You are getting the unexpected behaviour because you are mixing the old url
and new path
syntax. If you are using Django 2.0, change the import and update your URL patterns:
from django.urls import path
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
# ex: /polls/5/results/
path('<int:question_id>/results/', views.results, name='results'),
# ex: /polls/5/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
]
If you are using an earlier version of Django, you need to use regexes instead. For example, the Django 1.11 tutorial gets you to write:
from django.conf.urls import url
urlpatterns = [
# ex: /polls/
url(r'^$', views.index, name='index'),
# ex: /polls/5/
url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
# ex: /polls/5/results/
url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
# ex: /polls/5/vote/
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…