每当服务器上出现 500 错误时,我都会使用 Django 的内置功能向我发送错误报告。我使用 include_html
功能来获得更丰富的版本。
我真的希望登录用户(如果已登录)作为报告的一部分发送。我知道我可以使用 session ID 自己推断出它,但我真的更希望它被发送,这样我就不必每次都查找它。我怎样才能做到这一点?
最佳答案
你需要利用Custom Error Reports . settings.py 您需要创建自己的异常报告器类。不过,我还没有将它与 include_html
功能一起使用。
这是您需要执行的操作的示例。
from django.shortcuts import render
from django.views.debug import SafeExceptionReporterFilter
class CustomExceptionReporterFilter(SafeExceptionReporterFilter):
def get_request_repr(self, request):
result = u"User Info: \n"
if request.user.is_authenticated():
user = request.user
result += u"\nUser Id: {}".format(user.id)
else:
result += u"\nUser Id: Not logged in"
result += super(CustomExceptionReporterFilter, self).get_request_repr(request)
return result
关于python - 报告用户 Django 错误报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23582114/