Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created September 3, 2012 06:34
Show Gist options
  • Save svetlyak40wt/3607315 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/3607315 to your computer and use it in GitHub Desktop.
Django trace for superuser
# source: http://blog.lalf.ru/2012/01/django-traceback-production.html#more
from django.views.debug import technical_500_response
import sys
class UserBasedExceptionMiddleware(object):
def process_exception(self, request, exception):
if request.user.is_superuser:
return technical_500_response(request, *sys.exc_info())
# И в settings.py к настройке MIDDLEWARE_CLASSES допишем следующее:
# 'core.debug.UserBasedExceptionMiddleware',
# Чтобы получилось что-то такое:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'core.debug.UserBasedExceptionMiddleware',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment