运行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。
runserver
中出来的吗?Nginx / Apache?是什么样的设置? - Jack M.