I am trying the basic Django tutorial: https://docs.djangoproject.com/en/3.1/intro/tutorial01/
The admin page is up and running but getting a 404 on the http://localhost:8000/polls/ page:
I cannot understand what this code is doing:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls)
]
I didn't define any polls.urls
, so how will it know how to route the request?
Total beginner here. Coming from the old Tomcat/JBoss world.
'polls.urls'
means polls/urls.py
, i.e. you need to have a urls.py
in the polls
app folder.
The previous step in that tutorial asks you to create one:
https://docs.djangoproject.com/en/3.1/intro/tutorial01/#write-your-first-view
In the
polls/urls.py
file include the following code:from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), ]
The URL dispatcher then will concatenate the path in your main urls.py
('polls/'
) and the one in the polls/urls.py
(''
) to resolve the view name (views.index
).