Like many others I am having problems with part 1 of the tutorial. I get the message at the end of part 1 which says
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: |
|
- admin/
The current path, polls/
, didn’t match any of these.
I am amazed that I am seeing so many new users having this same problem, and this is not directly addressed in the tutorial itself. There are many wild and crazy ideas on the source of the problem and the potential fixes, including editing the code in VS code.
The problems seem to lie in mysite/urls.py and mysite/polls/urls.py so I have copied the contents of these two files here.
mysite/urls.py
from django.urls import include, path
urlpatterns = [
path("polls/", include("polls.urls")),
path("admin/", admin.site.urls),
]
mysite/polls/urls.py
from . import views
urlpatterns = [
path("", views.index, name="index"),
]
OS: Linux Mint 20.3
Python: 3.8.1
django: 4.2.7
Any assistance appreciated. Maybe we can improve the documentation for beginners to reduce the number who simply move on to others systems.
regards
Mike
Actually, the causes of this varies, because there are a number of different mistakes that can be made that result in this error.
One of the common errors is when someone is in the “inner” mysite
directory when they run startapp
instead of the “outer” mysite
.
In other words, the directory structure should look like this:
mysite/
mysite/
polls/
not
mysite/
mysite/
polls/
And yes, this is documented in the tutorial. It’s covered in the two paragraphs in the Creating the Polls app section after the “Projects vs apps” note box.
Many thanks for your response. I went to check the directory structure and confirmed that both the mysite and polls directories were in the outer mysite directory.
cheers
mike
Another file to verify location is that the urls.py files are in mysite/mysite/urls.py
and mysite/polls/urls.py
Your image implies that you’ve got a urls.py file in the outer mysite directory when it should be in the inner mysite.
Yes it wasn’t clear from the tutorial whether the urls.py file should be in the mysite or the mysite/mysite directory.
I checked my file layout -
but it doesn’t seem to have fixed the problem. I made sure I cleared the cache on my browser (firefox) that doesn’t seem to have changed anything.
cheers
Mike
Is there complete code for the first part of the tutorial on github or elsewhere? This would solve a lot of problems.
Mike
Thank you. Tutorial part 1 is now working.
Can I suggest the following improvements to the documentation:
- Inset section/place numbers in the documentation so that it is easier to refer to a particular spot.
- In the location of the urls.py files, these should be:
mysite/polls/urls.py and
mysite/mysite/urls.py
The latter should not be referred to a mysite/urls.py as this is misleading. If there was any numbering system, I would refer to the particular spot.
cheers Mike