Python Django返回一个奇怪的内部服务器错误,即使DEBUG=True

Python Django返回一个奇怪的内部服务器错误,即使DEBUG=True,python,django,apache,postgresql,ubuntu,Python,Django,Apache,Postgresql,Ubuntu,我有一个非常奇怪的情况,伙计们。Django的DEBUG等于True,但当我运行某个特定脚本时,它返回以下错误,与Django的标准DEBUG输出相反: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, ababab

我有一个非常奇怪的情况,伙计们。Django的DEBUG等于True,但当我运行某个特定脚本时,它返回以下错误,与Django的标准DEBUG输出相反:

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
输出。我还注意到,当我遍历mostView并将其添加到列表中时,没有出现错误


如果您能为我指出正确的方向,我将不胜感激。

您不应该在HttpResponse中包装查询集。看看Django视图文档,其中有很多使用示例:

看起来像是apache错误而不是Django,您确定
debug=True
?查看apache错误日志您没有将
请求
对象作为参数发送到
索引
方法。使用
return render()beginning@karthikr,使用return render()并没有解决问题:,那么我提到的其他问题呢?