Error 404 following a tutorial 1

Hi all. I have started following tutorial 1 Writing your first Django app, part 1 | Django documentation | Django and after completing all of the steps accordingly and trying to go to http://localhost:8000/polls/ I get a 404 error. I am sure I have saved the urls.py in polls app, but it seems like django does not see it and does not check for these urls. Could you please tell me what I am doing wrong?

my urls.py:

from django.contrib import admin
from django.urls import include, path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

What’s the content of polls.urls file?
Also note that you’re accessing polls and not polls/ (Note the trailing slash / )

In addition to @leandrodesouzadev comment, notice that the error in the browser window is not showing these other urls that you have defined.

I’m guessing the problem is that you made these entries in your polls/urls.py file instead of the mysite/urls.py.

Review very carefully the steps starting from Writing your first Django app, part 1 | Django documentation | Django. Pay particular attention to which files need to be modified.

1 Like

For anyone else having this problem, I figured it out. It’s not abundantly clear in the tutorial docs that the mysite/urls.py file you need to add the line to for the polls urlpattern is in the “inner” mysite folder. The error you see indicates that because it’s saying it has only found an admin pattern (by default the inner mysite/urls.py only has that pattern). Most likely you have edited the urls.py file in the “outer” mysite folder. That was my issue anyway, hope that helps others.

2 Likes