Created
June 25, 2015 01:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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