在使用manage.py runserver时,在Django中的错误上打印堆栈跟踪stdout [英] Print a stack trace to stdout on errors in Django while using manage.py runserver

查看:385
本文介绍了在使用manage.py runserver时,在Django中的错误上打印堆栈跟踪stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些搜索,但是我想知道是否有人有一个记录配置的代码段,以便Django只需输出一个堆栈跟踪到stdout(所以我可以看到它在终端窗口中)遇到错误时一个要求。这是专门用于本地开发/调试的,主要是在我做AJAX发布请求时,我必须看看Firebug中的HTML,以弄清楚错误发生了什么行。

解决方案

您可以创建一个中间件来执行此操作。以下是我用于项目的修改的片段:

  class ExceptionLoggingMiddleware(object):
def process_exception(self ,请求,例外):
import traceback
print traceback.format_exc()




I did some searching, but I'm wondering if anyone has a snippet of a logging configuration to get Django to just output a stack trace to stdout (so I can see it in the Terminal window) when it encounters an error during a request. This is specifically for local development/debugging and mainly for when I do AJAX post requests and I have to look at the HTML in Firebug to figure out what line the error occurred on.

解决方案

You can create a piece of middleware to do this. Here's a modified snippet I'm using for a project:

class ExceptionLoggingMiddleware(object):
    def process_exception(self, request, exception):
        import traceback
        print traceback.format_exc()

Place this handler in your middleware part of the Django settings.

这篇关于在使用manage.py runserver时,在Django中的错误上打印堆栈跟踪stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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