python - 报告用户 Django 错误报告

标签 python django

每当服务器上出现 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/

相关文章:

django - 如何使用字段名称获取 ManyToMany Manager 对象

python - pymongo 中的 Tailable 游标似乎已停止工作

python - 将帧合并为一个视频时如何避免系统死机

python - Pandas DataFrame 日期时间索引在 JSON 转换和重新转换后无法生存

Django 。如何从内容类型框架中获取字段的相关名称

python - 南 : how to ignore a changed model while creating a migration for an app

python - 将子线程中创建的对象返回到主线程中

python - 无法在 https 端口 (443) [Errno 10013] 上实例化 python BaseHTTPServer

C9平台上的Django消息框架问题

python - django 在 QuerySet 上使用 len() 时给出 TypeError