Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Django: Adds user information to the request's META dictionary, which helps when processing logs via mail_admins.
class ExceptionUserInfoMiddleware(object):
def process_exception(self, request, exception):
try:
user = request.user
if user.is_authenticated():
request.META['USER_ID'] = str(user.id)
request.META['USER_NAME'] = str("%s %s" % (user.first_name, user.last_name))
request.META['USER_EMAIL'] = str(user.email)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment