Hi all I'm having trouble solving this issue: If I turn DEBUG to False, I can't run manage.py runserver:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
Then, let's say I add something to ALLOWED_HOSTS:
ALLOWED_HOSTS = ['*']
or
ALLOWED_HOSTS = ['localhost']
or
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
Now, I can do ´manage.py runserver´ but the staticfiles don't work. Weird.
If I turn DEBUG to True, then it works with ALLOWED_HOSTS set to nothing, to localhost or to *. So, I guess the problem has to do with DEBUG. I don't understand it.
Best Answer
In
DEBUG
mode, the Django development server handles serving static files for you. However, this is not best for production as it's much more inefficient than a true server. See here.Check out here to learn out how to serve static files in production.
EDIT: Adding the following to answer @alejoss question about viewing error pages with DEBUG=True.
I added something like the following to my root
urls.py
file:You might need to alter a bit (i.e., the
400
and403
pages may need to be edited if your template names are different). Basically, this lets you visithttp://localhost/400
to see your400
error page,http://localhost/403
to see your403
error page, and so on.