1

I am trying to troubleshoot a 500 error, as whenever I set DEBUG = False in Django, I receive a 500 error.

I attempted to set ALLOWED_HOSTS = ['*']

I attempted to setup LOGGING to debug and force logging to console with a loop. However, it does not work, so there is a good chance it is not doing what I think it should be doing.

I have attached a snippet from my settings file:

settings.py:

DEBUG = False

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
        },
    },
}

for logger in LOGGING['loggers']:
    LOGGING['loggers'][logger]['handlers'] = ['console']


ALLOWED_HOSTS = ['*']
notlaughing
  • 177
  • 2
  • 12
  • Please share the error message and associated traceback. Otherwise people are left to guess why your project might throw a 500 when `DEBUG` is `True` (which is an odd situation, I'll admit). – Paul Bissex May 26 '20 at 02:04
  • I'm not sure how to get the traceback - could you elaborate? This is the only thing shown in the console: [26/May/2020 02:48:15] "GET /pets/api/v2/ HTTP/1.1" 500 27. - and the only message I get in the browser is:

    Server Error (500)

    – notlaughing May 26 '20 at 02:49
  • If `DEBUG = True` in your project's `settings.py` (which, from your description, it surely is), you should see a very informative error page when the error happens. It will include traceback information showing exactly where the error occurred. It also lets you see what the local variables were at key points in the execution before the fatal error happened. (The content is [like this example](http://dpaste.com/2JKK2FA) but prettier.) – Paul Bissex May 26 '20 at 19:25
  • @PaulBissex In my example above, it says 'DEBUG=False' - when 'DEBUG=True' it gave no errors and that was my dilemma. However, when I set it to false and also used the switch 'DEBUG_PROPAGATE_EXCEPTIONS = True' it gave me a nice stack trace. – notlaughing May 26 '20 at 22:09

2 Answers2

2

The solution to my problem ended up being to add the following command in settings.py

DEBUG_PROPAGATE_EXCEPTIONS = True

described here: https://docs.djangoproject.com/en/2.0/ref/settings/#debug-propagate-exceptions

In my particular instance, it turned out I was getting a value error which was fixed by performing a collectstatic

python manage.py collectstatic

Related:

ValueError: Missing staticfiles manifest entry for 'favicon.ico'

notlaughing
  • 177
  • 2
  • 12
0

The server itself needs to review the log files. The reason is that if django makes a mistake, it means setting.py interpreter that has not yet entered the file. The same reason you can see the logs on the server itself. All that is clearly written there

Here's a try to add it too, sometimes it can help settings.py

    MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware', #Добавляем до 'django.middleware.security.SecurityMiddleware',
]