在使用manage.py runserver时,在Django中的错误上打印堆栈跟踪stdout [英] Print a stack trace to stdout on errors in Django while using manage.py runserver
本文介绍了在使用manage.py runserver时,在Django中的错误上打印堆栈跟踪stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您可以创建一个中间件来执行此操作。以下是我用于项目的修改的片段:
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屋!
查看全文