#19875 closed Cleanup/optimization (fixed)
Tutorial should have include ALLOWED_HOSTS setting
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | ALLOWED_HOSTS, tutorial |
Cc: | timograham@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Got bit by 500 errors when switching to DEBUG=False.
As a total newbie, this was tough because a local install on my mac wasn't sending me email by default either.
I would recommend updating the tutorial to mention setting ALLOWED_HOSTS within the initial settings.py setup, perhaps to 127.0.0.1/localhost if the user is doing a local install.
Attachments (3)
Change History (19)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 12 years ago
Agreed that this is a problem that needs to be solved; equally hesitant about adding it to the early tutorials.
One possible approach would be to tackle an old feature request, and write a new tutorial on deployment. This would also give us a chance to set some best practices on "how to do it right", which is something that we've historically punted on. It's sure to be a bike shed discussion, but with a couple of judicious BDFL judgements, I'm sure we could get something we can all live with.
comment:3 by , 12 years ago
Is there an existing ticket for "deployment tutorial"? #19697 is at least closely related.
comment:5 by , 12 years ago
#20171 suggests adding documentation under DEBUG
noting that if you set it False
you must set ALLOWED_HOSTS
. It also contains a list of related tickets:
comment:7 by , 11 years ago
Cc: | added |
---|---|
Has patch: | set |
Current status of this:
- The deployment checklist has a note about
ALLOWED_HOSTS
. - The
ALLOWED_HOSTS
comment in the default project template was removed (probably in Aymeric's effort to simplify it). I've added it back in the attached patch as well as other relevant warnings in a couple places. - I like the idea offered in #20139: "Whenever starting the server in
DEBUG = False
andALLOWED_HOSTS = []
, display a warning on the console (stderr) that no request will be served because of the emptyALLOWED_HOSTS
setting." If someone agrees, we can open a new ticket.
by , 11 years ago
Attachment: | 19875.2.diff added |
---|
comment:8 by , 11 years ago
AFAIK it's a conscious choice not to talk about anything related to deployment (like ALLOWED_HOSTS) in the tutorial. The tutorial must stay focused on its main purpose; it mustn't be a default place for docs that don't fit anywhere else.
I strongly believe that insufficient information is worse than no information at all, and for this reason I would really like if we could keep settings.py as is (although I don't have much hope and I'm pretty sure settings.py will grow some cruft again; well, at least I'll voice my opposition).
There's tons of useful advice to give about deployment; the deployment checklist helps much more than random, piecemeal advice in settings.py. I have to admit that I don't care very much about users who can't be bothered to read the docs, too.
comment:9 by , 11 years ago
The tutorial talks about setting DEBUG
to False
in order to use your own 404.html, 500.html, etc. templates. The note appears right under that section so if people try it they will be aware.
I'm fine with keeping settings.py as is.
What do you think about the suggestion of modifying runserver
so it won't work with a bad configuration? I feel like that should eliminate this problem for non-deployment cases.
comment:10 by , 11 years ago
I think the console should warn the user, if ALLOWED_HOSTS is empty, that it will mean the site won't work when DEBUG is False (whatever the current state of DEBUG).
It's caught me out more than once...
by , 11 years ago
Attachment: | 19875.3.diff added |
---|
comment:11 by , 11 years ago
New patch adds logic so runserver
won't serve any requests if DEBUG
is False
and ALLOWED_HOSTS
is empty (I'm unsure if this needs tests -- tests.admin_scripts.ManageRunserver
mocks the run
method so I don't think anything in that method is actually tested).
Also removed the note in the previous patch from settings.py
.
comment:12 by , 11 years ago
Small nitpick about self.stderr.write/exit
, I think that this could be replaced by raising CommandError
instead.
comment:13 by , 11 years ago
Thanks, updated in a pull request. Moved the logic to the handle()
method and also added a test. https://github.com/django/django/pull/1249
comment:14 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I'm hesitant to add extra verbiage at that stage of the tutorial involving something that you don't actually need until much later, whenever you try flipping
DEBUG
toFalse
. I was hoping that havingDEBUG
andALLOWED_HOSTS
very close to each other in the template settings file, and a comment onALLOWED_HOSTS
saying "required if DEBUG is False", would be enough - but apparently it isn't. Maybe we could add another comment above theDEBUG
setting insettings.py
specifically reminding you to checkALLOWED_HOSTS
if you flip it toFalse
?Accepting because I think this is a problem that should be solved; not sure yet if adding to the tutorial is the right solution.