问题描述
当我追加 - traceback --verbosity 2
时,Django的 runserver
命令不会输出堆栈跟踪: ➫python manage.py runserver --traceback --verbosity 2
验证模型...
0发现错误
2013年7月24日 - 11:45:12
Django版本1.5.1,使用设置'base.settings'
开发服务器运行在http: /127.0.0.1:8000/
使用CONTROL-C退出服务器。
[24 / Jul / 2013 11:45:27]POST / login / get_associations / HTTP / 1.0500 13220
有没有其他命令行开关或记录配置,我可以添加以获取 runserver
打印一个堆栈跟踪,当有一个 500
?
同意这样很方便,特别是以MVVM为中心的应用程序开发角/琥珀色前端)。另外这有助于其他人测试前端。
正如你所提到的,这不是由 DEBUG = True
。您可以通过在 settings.py 文件中添加以下内容来运行 ./ manage.py runserver
添加一个堆栈跟踪:
LOGGING = {
'version':1,
'handlers':{
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
},
},
' ':{
'django.request':{
'handlers':['console'],
'propagate':True,
'level':'DEBUG'
}
},
}
此语法来自Django文档,并可进一步修改以增加或减少控制台的数量记录。
另请注意, 5XX 的回复提高为ERROR我ssages和 4XX 响应作为警告消息引发。
Django's runserver
command doesn't output a stack trace when I append --traceback --verbosity 2
:
➫ python manage.py runserver --traceback --verbosity 2
Validating models...
0 errors found
July 24, 2013 - 11:45:12
Django version 1.5.1, using settings 'base.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[24/Jul/2013 11:45:27] "POST /login/get_associations/ HTTP/1.0" 500 13220
Are there other command line switches or logging configuration I can add to get runserver
to print a stack trace when there is a 500
?
Agreed that this is convenient, especially for MVVM-centric app development (e.g. Angular/Ember front-end). Also this is helpful when others are testing out the front-end.
As you mentioned, this isn't provided by DEBUG=True
. You can add a stacktrace when running ./manage.py runserver
by adding the following to the settings.py file:
LOGGING = {
'version': 1,
'handlers': {
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
},
},
'loggers': {
'django.request': {
'handlers':['console'],
'propagate': True,
'level':'DEBUG',
}
},
}
This syntax comes from the Django documentation Configuring Logging and can be further modified to increase or decrease the amount of console-logging.
Also note that 5XX responses are raised as ERROR messages and 4XX responses are raised as WARNING messages.
这篇关于来自manage.py runserver的堆栈跟踪不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!