Skip to content

Instantly share code, notes, and snippets.

@karthikbgl
Created June 25, 2015 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthikbgl/8d97c428993a60f64ecb to your computer and use it in GitHub Desktop.
Save karthikbgl/8d97c428993a60f64ecb to your computer and use it in GitHub Desktop.
Override the standard 500 error page to display the stack trace if certain conditions are met. The advantage of overriding the server error handler is, it keeps everything else intact - example all the error emails, etc.
from django.views.debug import technical_500_response
from django.views.defaults import server_error
def server_error_handler(request):
ip_address = request.META.get("HTTP_X_FORWARDED_FOR", request.META.get("REMOTE_ADDR"))
if ip_address in settings.ALLOWED_IPS_FOR_DEBUG_SCREEN: #or request.user.is_staff
return technical_500_response(request, *sys.exc_info())
return server_error(request)
from .handler_500 import server_error_handler
handler500 = server_error_handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment