Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2010 05:16
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sidmitra/646372 to your computer and use it in GitHub Desktop.
Middleware to add user info to the current django request
class ExceptionUserInfoMiddleware(object):
Adds user details to request context on receiving an exception, so that they show up in the error emails.
Add to settings.MIDDLEWARE_CLASSES and keep it outermost(i.e. on top if possible). This allows
it to catch exceptions in other middlewares as well.
def process_exception(self, request, exception):
Process the exception.
- `request`: request that caused the exception
- `exception`: actual exception being raised
if request.user.is_authenticated():
request.META['USERNAME'] = str(request.user.username)
request.META['USER_EMAIL'] = str(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment