Skip to content

Instantly share code, notes, and snippets.

@nick-merrill
Created July 3, 2014 18:22
Show Gist options
  • Save nick-merrill/a18f6cba8bd0215e1847 to your computer and use it in GitHub Desktop.
Save nick-merrill/a18f6cba8bd0215e1847 to your computer and use it in GitHub Desktop.
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