如何在我的Django 500.html页面中添加堆栈跟踪? [英] How do I include a stacktrace in my Django 500.html page?

查看:91
本文介绍了如何在我的Django 500.html页面中添加堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Django 1.0 ,我很接近部署我的应用程序。因此,我会将DEBUG设置更改为False。

I'm running Django 1.0 and I'm close to deploying my app. As such, I'll be changing the DEBUG setting to False.

据说,我仍然希望将stacktrace包含在我的500.html页面上发生错误。通过这样做,用户可以复制和粘贴错误,并轻松地将其发送给开发人员。

With that being said, I'd still like to include the stacktrace on my 500.html page when errors occur. By doing so, users can copy-and-paste the errors and easily email them to the developers.

有关如何最好地解决此问题的任何想法?

Any thoughts on how best to approach this issue?

推荐答案

自动登录500s,这样:

Automatically log your 500s, that way:


  • 你知道什么时候发生。

  • 你不需要依赖用户发送堆栈跟踪。

Joel建议甚至在您的应用程序遇到故障时自动创建错误跟踪器中的故障单。就个人而言,我使用开发人员可以订阅的堆栈跟踪,urls等创建一个(私人)RSS feed。另一方面,向用户显示堆栈跟踪

Joel recommends even going so far as automatically creating tickets in your bug tracker when your application experiences a failure. Personally, I create a (private) RSS feed with the stacktraces, urls, etc. that the developers can subscribe to.

可能会泄漏恶意用户可能用来攻击您的站点的信息。过分详细的错误消息是SQL注入攻击的经典步骤之一。

Showing stack traces to your users on the other hand could possibly leak information that malicious users could use to attack your site. Overly detailed error messages are one of the classic stepping stones to SQL injection attacks.

编辑(添加代码示例以捕获回溯):

Edit (added code sample to capture traceback):

您可以从sys.exc_info调用获取异常信息。虽然格式化回溯显示来自追溯模块:

You can get the exception information from the sys.exc_info call. While formatting the traceback for display comes from the traceback module:

import traceback
import sys

try:
    raise Exception("Message")
except:
    type, value, tb = sys.exc_info()
    print >> sys.stderr,  type.__name__, ":", value
    print >> sys.stderr, '\n'.join(traceback.format_tb(tb))

打印:

Exception : Message
  File "exception.py", line 5, in <module>
    raise Exception("Message")

这篇关于如何在我的Django 500.html页面中添加堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆