On the Writing your first Django app, part 1 page, at the point where ‘mysite.urls.py’ is modified. Running the server will return a 404 error.
This is because in ‘mysite/urls.py’ only ‘polls/’ and ‘admin/’ are mapped.
In order to make it work, add the following line:
path(“”, include(“polls.urls”))
as the first entry to eliminate the error.
Welcome @cyberwip !
That step is neither required nor in alignment with what the Django tutorial is trying to teach.
Aside from the very first step (installation), at no time does the tutorial ask you to issue a request of a “bare” (no-path) url. If you follow the steps of the tutorial as written, you will not receive an error.
Thanks for the response Ken, but if you search the web for the same problem you will see that it occurs regularly, and the tutorial had at that point demonstrated that this was the procedure to run the app.
So I had a hot key assigned for the evaluation server which I don’t think is beyond practical, and at that point it was said to run the app.
I saw no notice on the first run that this was a special case and had not yet gotten to the point where the path was even stated.
At that point, this was the default app on that address and a 404 should not have resulted.
It’s a simple fix, to a seemingly recurring problem.
I did see by typing in the full path to the app I arrived at the polls page, but again, this is the default app, so I see no harm in setting it as the default page, at least at this point.
The point was made because this has happened on numerous occasions.
It’s a simple solution to a problem. And nowhere when it said to start the server did it say “but do not use the same URL.”
I think it’s a great idea!
I’ve also found other errors or omissions in the tutorial which I am actually documenting right now. So expect more.
The tutorial explicity identifies what urls you are to enter.
In the section: Writing your first Django app, part 1 | Django documentation | Django
Go to http://localhost:8000/polls/ in your browser, and you should see the text “Hello, world. You’re at the polls index.”, which you defined in the index view.
Page not found?
If you get an error page here, check that you’re going to http://localhost:8000/polls/ and not http://localhost:8000/.
So yes, it does explicitly state to not use the bare url.
I suggest a more careful reading of the tutorial. That’s not to say that there’s aren’t errors in it, but every “error” I can remember seeing posted here has been an issue of not fully reading the tutorial.
It does say:
The idea behind
include()
is to make it easy to plug-and-play URLs. Since polls are in their own URLconf (polls/urls.py
), they can be placed under “/polls/”, or under “/fun_polls/”, or under “/content/polls/”, or any other path root, and the app will still work.
I did read it! “any other path root”
Why don’t you explain what is wrong with my solution?
- It’s not necessary.
- There is no value in having two different urls leading to the same page.
- It potentially creates confusion by creating multiple URLs leading to the same views.
- It’s not in alignment with the ultimate goals of what the tutorial is trying to teach.
- It can give the impression that it’s something that needs to be done to make your system “work”.