Settings ALLOWED_HOSTS

As you just started recording your lessons, I think it would be nice to update lesson 1 to have this new ALLOWED_HOSTS settings, it was added in all Django versions from 1.3 and beyond.

Sorry You must be a logged in, registered user to answer a question.

Answers

Agreed, this probably needs to be addressed. Apparently, Django 1.4.5 (the version downloaded into my vagrant VM) requires the ALLOWED_HOSTS setting to match the url you're accessing, even in the development server, if DEBUG is set to false. That line where you said "Set DEBUG to false in your local copy, and it still works!"? That threw me for a loop when every url in my local copy started throwing 500 errors. I ended up having to run a local SMTP server to catch the error message just to figure out what was going wrong. Setting ALLOWED_HOSTS = ['*'] is obviously not production server best practices, but it allowed me to run locally and successfully deploy to Heroku.

kennethlove - I believe I had the same experience as shamatdotnet. As a test, resetting my ALLOWED_HOSTS to the default value of [] causes my dev environment to throw 500 errors for every route / url (DEBUG set to False). With DEBUG = True, this is not the case
Arne Fostvedt on
Running with Django 1.5 here...if DEBUG = False...ALLOWED_HOSTS should match your Heroku hostname in base.py and be set to ['localhost'] in local.py. At least that's what's working for me. Otherwise, literally everything throws a 500 error with DEBUG=False.
John Brewer on
I haven't had that experience at all, actually. Are you sure you restarted the dev server after taking it out of `DEBUG = False` mode?
kennethlove (Staff) on

it exists in 1.3, 1.4, and 1.5, yes, but it was just added this last week. We'll cover it in future episodes, I'm sure.