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)
Using the URLconf defined in mysite.urls
, Django tried these URL patterns, in this order:
- 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!
2 Likes
THIS!!! Oh my god. I looked and looked for my problem, trying everything. I’m in a new IDE and didn’t realize it doesn’t autosave! It works great now!!!
Add the following path entry as the first (above “polls/”) in mysite/urls.py.
path(“”, include(“polls.urls”)),
You should now have 3.
The issue was resolved (and marked as solved), without adding this unnecessary entry.