-1

伙计们,我有一个非常奇怪的情况。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并将其添加到列表时没有错误。

任何能指出我正确方向的东西都将不胜感激。

4

1 回答 1

1

您不应该在 HttpResponse 中包装查询集。查看 Django 视图文档,其中有很多使用示例:https ://docs.djangoproject.com/en/1.5/topics/http/views/

于 2013-07-31T16:35:21.783 回答