有没有办法向管理员显示Django调试堆栈跟踪页面,即使设置中DEBUG = False? [英] is there a way to show the Django debug stacktrace page to admin users even if DEBUG=False in settings?
本文介绍了有没有办法向管理员显示Django调试堆栈跟踪页面,即使设置中DEBUG = False?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
情景:而不是我不得不SSH到一个盒子来检索一个堆栈跟踪,我更喜欢非技术的同事只是给我发送错误!
Scenario: instead of me having to SSH into a box to retrieve a stacktrace, I'd prefer non-techie co-workers to just email me the error!
Django有没有办法或钩子来做这样的事情?例如
Is there a way or hook in Django to do something like this? e.g.
def 500_error_happened(request): # psuedocode >__<
if request.user.is_staff:
show_the_debug_stack_trace_page()
else:
show_user_friendly_500_html_page()
推荐答案
找到答案!您可以使用显示 technical_500_response
的超级用户的中间件:
found an answer! You can use a middleware which displays technical_500_response
to 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/ )
这篇关于有没有办法向管理员显示Django调试堆栈跟踪页面,即使设置中DEBUG = False?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文