"Writing Your First Django App, Part 1" error with Polls

Working through part 1 of the tutorial and am getting this error when trying to access polls in my internet browser:

"# Page not found (404)

Request Method: GET
Request URL: http://localhost:8000/polls/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

  1. admin/

The current path, polls/, didn’t match any of these."

I have triple checked my code, but here it is:

polls\urls.py

from django.urls import path

from . import views

urlpatterns = [
    path("", views.index, name="index"),
]

mysite\urls.py

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

urlpatterns = [
    path("polls/", include("polls.urls")),
    path("admin/", admin.site.urls),
]

polls\views.py

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

you not set app_name.

# polls/urls.py

from django.urls import path

from . import views

# add
app_name = 'polls'

urlpatterns = [
    path("", views.index, name="index"),
]

Added. Still getting same error.

from django.urls import path

from . import views

app_name = 'polls'

urlpatterns = [
    path("", views.index, name="index"),
]

Remove the app_name because it won’t affect this error and isn’t used at this point of the tutorial.

Your files look fine to me, so I’m puzzled! I would double check your file structure matches that in the tutorial, and that you have saved all the files in your editor (I’ve sometimes had errors and realised I hadn’t saved my changes!).

2 Likes

Hadn’t saved the changes. Doing so fixed the error. Thanks!

1 Like