Setting DEBUG = False causes 500 Error Setting DEBUG = False causes 500 Error django django

Setting DEBUG = False causes 500 Error


Django 1.5 introduced the allowed hosts setting that is required for security reasons. A settings file created with Django 1.5 has this new section which you need to add:

# Hosts/domain names that are valid for this site; required if DEBUG is False# See https://docs.djangoproject.com/en/1.9/ref/settings/#allowed-hostsALLOWED_HOSTS = []

Add your host here like ['www.beta800.net'] or ['*'] for a quick test, but don't use ['*'] for production.


I know this is late but I ended up here with a search for my error 500 with DEBUG=False, in my case it did turn out to be the ALLOWED_HOSTS but I was using os.environ.get('variable') to populate the hosts, I did not notice this until I enabled logging, you can log all errors to file with the below and it will log even when DEBUG=False:

# settings.pyLOGGING = {    'version': 1,    'disable_existing_loggers': False,    'formatters': {        'verbose': {            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",            'datefmt' : "%d/%b/%Y %H:%M:%S"        },        'simple': {            'format': '%(levelname)s %(message)s'        },    },    'handlers': {        'file': {            'level': 'DEBUG',            'class': 'logging.FileHandler',            'filename': 'mysite.log',            'formatter': 'verbose'        },    },    'loggers': {        'django': {            'handlers':['file'],            'propagate': True,            'level':'DEBUG',        },        'MYAPP': {            'handlers': ['file'],            'level': 'DEBUG',        },    }}


I encountered the same issue just recently in Django 2.0. I was able to figure out the problem by setting DEBUG_PROPAGATE_EXCEPTIONS = True. See here: https://docs.djangoproject.com/en/2.0/ref/settings/#debug-propagate-exceptions

In my case, the error was ValueError: Missing staticfiles manifest entry for 'admin/css/base.css'. I fixed that by locally running python manage.py collectstatic.