我有一个非常奇怪的情况。 Django的DEBUG等于True,但是当我运行某个特定的脚本时,它会返回以下错误,而不是Django的标准调试输出:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, ababab@gmail.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.2.14 (Ubuntu) Server at ababab.com Port 80
为什么会发生这种情况?我注意到当我删除下面的代码时,我没有错误。观点是:
import datetime
from datetime import datetime, date, timedelta
def index():
mostViewed = ProfileVisits.objects.filter(timestamp__gt = datetime.now() - timedelta(7))[0]
return HttpResponse(mostViewed)
我注意到当我在行底部行之前插入行mostViewed = len(mostViewed)
时,我得到了1
的输出,这是预期的。我还注意到,当我遍历 mostViewed 并将其添加到列表中时没有错误。
任何能指引我朝正确方向发展的事情都会非常感激。
答案 0 :(得分:1)
您不应该在HttpResponse中包装查询集。看一下Django视图文档,其中有很多用法示例:https://docs.djangoproject.com/en/1.5/topics/http/views/