[Solved]-Including Local Variables in Django Error Emails

14👍

It’s really simple to set this up. Just put 'include_html': True in the logging config of whichever handler is sending error emails for you.

For example (this is the default logging handler aside from the “include_html” line):

'handlers': {
    'mail_admins': {
        'level': 'ERROR',
        'filters': ['require_debug_false',],
        'class': 'django.utils.log.AdminEmailHandler',
        'include_html': True
    }
}

This includes an html attachment in the error email with the contents of the error page you get when DEBUG=True. The Django docs have a few more details and a note about security.

You could also look at setting up a logging handler which uses subclasses of django.utils.log.AdminEmailHandler and django.views.debug.ExceptionReporter if you need to customize things a lot more.

👤Kevin

Leave a comment