Skip to content

Instantly share code, notes, and snippets.

View benjaoming's full-sized avatar

Benjamin Balder Bach benjaoming

View GitHub Profile
@benjaoming
benjaoming / add_user_info_to_request_middleware.py
Last active February 28, 2019 12:26 — forked from sidmitra/add_user_info_to_request_middleware.py
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.
Origin: https://gist.github.com/646372
"""