The best way to do this is to set up a logging handler for django.requests
. You do this by adding the LOGGING
setting to your settings.py
file. An example is included below:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'console': {
'level': 'NOTSET',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'NOTSET',
},
'django.request': {
'handlers': ['console'],
'propagate': False,
'level': 'ERROR'
}
}
}
With this in place, you'll see a nice stack trace in your terminal every time a 500 response is returned.
For more information on Django's implementation of the Python logger, see the documentation about logging.