When I get an error exception email from my Django site it would be useful to see the User and/or UserProfile information for the currently logged in user. How do I add this to the Django site exception error emails?
Django appends repr(request) at the end of the e-mail. Using the default wsgi development server you can find the logged in user as
'LOGNAME': 'myuser',
This may be hidden in some e-mail clients as it is wrapped in angle brackets.
<WSGIRequest
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
...
'LOGNAME': 'myuser',
...
wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>
Also, you can implement a custom middleware that implements the process_exception method:
process_exception(self, request, exception)
request is an HttpRequest object. exception is an Exception object raised by the view function.
Django calls process_exception() when a view raises an exception. process_exception() should return either None or an HttpResponse object. If it returns an HttpResponse object, the response will be returned to the browser. Otherwise, default exception handling kicks in.
Again, middleware are run in reverse order during the response phase, which includes process_exception. If an exception middleware return a response, the middleware classes above that middleware will not be called at all.