I use Django 1.6.5 in my program txsite with the settings:
DEBUG = True
I set DEBUG to False, but when I
runserver, I get the following error:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
I tried setting
ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] but I get the same error.
anyone know how to figure it out?
ALLOWED_HOSTS = ['*']
Less secure if you’re not firewalled off or on a public LAN, but it’s what I use and it works.
EDIT: Interestingly enough I’ve been needing to add this to a few of my 1.8 projects even when
DEBUG = True. Very unsure why.
Your solution might be to add the original IP and/or hostname also
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '111.222.333.444', 'mywebsite.com']
Basically the host header (or X-Forwarded-Host if USE_X_FORWARDED_HOST is enabled) should match one of the values in ALLOWED_HOSTS.
Make sure it’s not redefined again lower down in your settings.py. The default settings has:
ALLOWED_HOSTS = 
if DEBUG is False, you also need to properly set the ALLOWED_HOSTS
setting. Failing to do so will result in all requests being returned
as “Bad Request (400)”.
I am using something like this:
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'www.mysite.com']