Working through the 2.2 tutorial I got momentarily stuck at
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.
What I got was a 404. Debug information of the built-in web server
indicated that it wasn't aware of the `polls/` path. Copy-paste of .py
code from the tutorial to the editor didn't help.
The issue was I created `urls.py` in the //outer// (`/somepath/mysite/`),
and not the //inner// (`/somepath/mysite/mysite`) mysite directory. Once
I understood what the problem was, the web server error message made
sense, which was nice ;)
Documentation is consistent, in a sense that it tells the reader to create
urls.py as `polls/urls.py` and then as `mysite/urls.py`, so it can be
concluded that the author meant `mysite/polls` and `mysite/mysite`,
respectively. However, the fact, that django uses the same directory name
at two levels is a trap for newbies.
I would like to propose two possible fixes to this issue:
1. After the contents of mysite/urls.py file add //Your mysite directory
should now look like:(…) // followed by the directory listing, similarly
to how polls/ directory content is shown earlier in the tutorial.
2. Add //'If you see `Not Found: /polls/` error message in the server
output then there's a problem with your mysite/urls.py file. Make sure you
edited the file in the inner //mysite// directory (at the same filesystem
level as the //polls// directory). //, or similar text to the "Page not
found" help inset.
Any of them should help the stray reader.
Other versions of the tutorial (I checked 3.0 and dev) use the same
wording and might benefit from the change.
--
Ticket URL: <https://code.djangoproject.com/ticket/31554>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Desmond Nyamador
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:1>
* status: assigned => closed
* version: 3.0 => 2.2
* resolution: => fixed
Comment:
Hi, I've gone through the documentation and it says at a point "To create
a URLconf in the polls directory, create a file called urls.py. Your app
directory should now look like:". I believe specifying the word "app" says
it all.
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:2>
Comment (by Paweł Brodacki):
Replying to [comment:2 Desmond Nyamador]:
> Hi, I've gone through the documentation and it says at a point "To
create a URLconf in the polls directory, create a file called urls.py.
Your app directory should now look like:". I believe specifying the word
"app" says it all.
Hi,
Once you know it says all, it does. However, before you do, it may be not
obvious.
If you google for `django tutorial 404` you'll find the proof that people
are misreading the tutorial instructions. Unless it's an intended effect,
calculated to make the reader pay attention, I believe it would be nice if
people didn't have to go to Stack Overflow to get past the tutorial.
Your call :)
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:3>
* has_patch: 1 => 0
* resolution: fixed => invalid
Comment:
Tutorial is really descriptive, we ask to add `urls.py` in app directory.
Moreover all expected files are listed below:
{{{
polls/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
urls.py
views.py
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:4>
* status: closed => new
* resolution: invalid =>
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:5>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:6>
* status: new => closed
* resolution: => invalid
* stage: Accepted => Unreviewed
Comment:
Desmond, please don't reopen invalid tickets.
--
Ticket URL: <https://code.djangoproject.com/ticket/31554#comment:7>