Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33249 closed Bug (invalid)

Writing your first Django app, part 3, Initial Path missing '/'

Reported by: Eric Jonathan Owned by: nobody
Component: Documentation Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

O/S: Windows 10
Python Version 3.10.0
Django 3.2.8

Following the tutorial at the "Writing your first Django app, part 3" (https://docs.djangoproject.com/en/3.2/intro/tutorial03/),
at the:

poll/urls.py

example, currently, it's

urlpatterns = [
    # ex: /polls/
    path('', views.index, name='index'),
    # ex: /polls/5/
    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'),
]

With error:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/polls/6/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

polls [name='index']
polls <int:question_id>/ [name='detail']
polls <int:question_id>/results/ [name='results']
polls <int:question_id>/vote/ [name='vote']
admin/
The current path, polls/6/, 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.

It should be:

urlpatterns = [
    path('', views.index, name='index'),
    path('/<int:question_id>/', views.detail, name='detail'),
    path('/<int:question_id>/results/', views.results, name='results'),
    path('/<int:question_id>/vote/', views.vote, name='vote'),
]

With result:

You're looking at question 6.

Change History (2)

comment:1 by Eric Jonathan, 3 years ago

Resolution: fixed
Status: newclosed

When I did mysite/urls.py,

urlpatterns = [

path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),

]

I missed the '/' on the polls,

polls
instead of
polls/

comment:2 by Jacob Walls, 3 years ago

Easy pickings: unset
Keywords: example error removed
Resolution: fixedinvalid
Note: See TracTickets for help on using tickets.
Back to Top