简体   繁体   English

Django日志记录引发500内部服务器错误

[英]Django logging throws 500 internal server error

I am having problems logging in my Django project. 登录我的Django项目时遇到问题。

In my view.py in an "application" I am doing the following: 在我的view.py中的“应用程序”中,我正在执行以下操作:

import logging

logging.basicConfig(filename="django.log",level=logging.DEBUG)

def request(request):
    logging.debug("test debugging")

with a django.log file in the same directory as the view.py file. 使用与django.log文件位于同一目录中的view.py文件。

Now when making a request from the browser I keep getting a 500 Internal Server error as shown in Firebug. 现在,当从浏览器发出请求时,我不断收到500内部服务器错误,如Firebug中所示。 I can get logging to work just fine when I simply run it through the interactive python shell or executing it from a .py file like the following: 当我只是通过交互式python shell运行它或从.py文件执行它时,我可以让日志工作正常,如下所示:

import logging

logging.basicConfig(filename="django.log",level=logging.DEBUG)

def testLogging():
    logging.debug("test debugging")

if __name__ == "__main__"
    testLogging()

, and then executing python nameOfFile.py . ,然后执行python nameOfFile.py

What am I doing wrong? 我究竟做错了什么? I am running Django 1.1.1 and Python 2.6.5. 我正在运行Django 1.1.1和Python 2.6.5。 Maybe I should upgrade Django? 也许我应该升级Django?

Could it be related to permissions? 它可能与权限有关吗? I can imagine that in a web-server environment, writing to a file may be restricted. 我可以想象,在Web服务器环境中,写入文件可能会受到限制。 In truth, I don't know, but please check the official Django logging documentation - it uses the standard logging module, but you may have to configure it differently. 事实上,我不知道,但请检查Django官方日志记录文档 - 它使用标准日志记录模块,但您可能需要以不同方式配置它。

Is that your entire view? 那是你的全部观点吗? It would have been helpful to post the actual traceback, but note that a view must return an HttpResponse , even if it's an empty one. 发布实际回溯会很有帮助,但请注意,视图必须返回HttpResponse ,即使它是空的。 So if that is your entire view, the 500 error is probably happening because you're not returning anything. 因此,如果这是您的整个视图,可能会发生500错误,因为您没有返回任何内容。

Add return HttpResponse() to the end of that view, and if that still doesn't work, please post the traceback itself. return HttpResponse()添加到该视图的末尾,如果仍然无效,请发布回溯本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM