Is there a way to show the Django stacktrace debug page for admin users, even if DEBUG = False in the settings?

Scenario: instead of having SSH in the stacktrace retrieval field, I would prefer non-technical peers to just send me an error!

Is there a way or hook in Django to do something like this? eg.

def 500_error_happened(request): # psuedocode >__< if request.user.is_staff: show_the_debug_stack_trace_page() else: show_user_friendly_500_html_page() 
+4
source share
2 answers

found the answer! You can use middleware that displays technical_500_response for superusers:

 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()) 

(from https://djangosnippets.org/snippets/935/ )

0
source

You might want to take a look at Sentry:

https://github.com/getsentry/sentry

With this, you can record the errors and stacks that you usually see with DEBUG = True, aggregate them and study them more deeply. Sentry can be configured to send email to you so that you are instantly notified.

Another option that does not require a new dependency is to use AdminEmailHandler :

https://docs.djangoproject.com/en/dev/topics/logging/#django.utils.log.AdminEmailHandler

However, some information that may be required for debugging may be sensitive and should not be sent by email. That's why even the Django documents mentioned above recommend using something like Sentry.

+2
source

Source: https://habr.com/ru/post/1481334/


All Articles