Django未处理的异常响应状态代码
运行 django 1.3。如果我在视图中有未处理的异常,例如
def test(request):
raise Exception('error')
获取页面(此处通过 wget):
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html'
[ <=> ] 218 --.-K/s in 0s
2011-08-04 17:47:43 (14.9 MB/s) - `index.html' saved [218]
index.html 的内容:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>Unhandled Exception</title>
</head><body>
<h1>Unhandled Exception</h1>
<p>An unhandled exception was thrown by the application.</p>
</body></html>
现在的问题是:为什么响应状态代码为 200?它应该是 500。
编辑: 在 lighttpd 上运行
manage.py runfcgi --settings=$SETTINGS socket=$SOCKET pidfile=$PIDFILE method=prefork minspare=1 maxspare=1 maxchildren=10 maxrequests=100"
在 settings.py 中使用命令 DEBUG=FALSE 。如果我更改为 DEBUG=TRUE,则响应状态代码正确为 500。
Running django 1.3. If I have an unhandled exception in a view, e.g.
def test(request):
raise Exception('error')
GETing the page (here via wget):
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html'
[ <=> ] 218 --.-K/s in 0s
2011-08-04 17:47:43 (14.9 MB/s) - `index.html' saved [218]
Contents of index.html:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>Unhandled Exception</title>
</head><body>
<h1>Unhandled Exception</h1>
<p>An unhandled exception was thrown by the application.</p>
</body></html>
And now to the question: why is the response status code 200? It should be 500.
EDIT:
Run on lighttpd with command
manage.py runfcgi --settings=$SETTINGS socket=$SOCKET pidfile=$PIDFILE method=prefork minspare=1 maxspare=1 maxchildren=10 maxrequests=100"
DEBUG=FALSE in settings.py. If I change to DEBUG=TRUE, the response status code is correctly 500.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
DEBUG = False
它将尝试运行500.html
模板。你创建了那个文件吗?With
DEBUG = False
it will try to run the500.html
template. Have you created that file?