2013-07-31 25 views
-1

我有一个很奇怪的情况。 Django的DEBUG等于真,但是当我运行某些特定的脚本返回下面的错误,而不是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, [email protected] 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

看起来像apache错误不是django,你确定'debug = True'吗?检查你的Apache错误日志 – dm03514

+2

你没有发送'request'对象作为'index'方法的参数。使用'return render()'代替 – karthikr

+0

另外,在开始时删除'import datetime' – karthikr

回答

相关问题