调试mod_wsgi上的Django代码(如何访问['wsgi.errors'])

时间:2021-12-23 23:05:20

I'm getting started with developing Django code on a server, running on top of Apache/mod_wsgi.

我开始在服务器上开发Django代码,运行在Apache / mod_wsgi之上。

I'm looking to understand a few things:

我想了解一些事情:

  1. What techniques are normally used to debug applications running on the server?

    通常使用哪些技术来调试服务器上运行的应用程序?

  2. Specifically, I'm trying to just use "print" debugging for now. But I can't seem to get print statements to work. I'm printing to stderr, but I'm not sure which log file I should be looking at. According to this, I should be using environ['wsgi.errors'], but how do I access that from my Django code?

    具体来说,我现在正试图使用​​“打印”调试。但我似乎无法让print语句起作用。我打印到stderr,但我不确定我应该查看哪个日志文件。根据这个,我应该使用environ ['wsgi.errors'],但是如何从我的Django代码中访问它?

Thanks!

EDIT: By the way, adding the line print >> sys.stderr, 'message ...' not only doesn't seem to print to any log file, it causes parts of my application to simply not load.

编辑:顺便说一下,添加行print >> sys.stderr,'message ...'不仅不会打印到任何日志文件,它会导致我的应用程序的部分内容无法加载。

1 个解决方案

#1


5  

  1. Try using the django debug toolbar. It can help a great deal with debugging when you can't actually use a debugger.

    Really though, debugging should be done on your development machine. I have yet to see a code issue in production with django that wasn't also occurring on my dev box.

    尝试使用django调试工具栏。当您无法实际使用调试器时,它可以帮助您进行大量调试。实际上,应该在您的开发机器上进行调试。我还没有在django的生产中看到代码问题,这个问题在我的开发盒上也没有发生。

  2. You usually can't print in mod_wsgi. Use the logging module instead. That's really what you want, and the debug toolbar will show you log statements in the page, so you don't even have to look at the file.

    你通常无法在mod_wsgi中打印。请改用日志记录模块。这真的是你想要的,调试工具栏会在页面中显示日志语句,所以你甚至不必查看文件。

#1


5  

  1. Try using the django debug toolbar. It can help a great deal with debugging when you can't actually use a debugger.

    Really though, debugging should be done on your development machine. I have yet to see a code issue in production with django that wasn't also occurring on my dev box.

    尝试使用django调试工具栏。当您无法实际使用调试器时,它可以帮助您进行大量调试。实际上,应该在您的开发机器上进行调试。我还没有在django的生产中看到代码问题,这个问题在我的开发盒上也没有发生。

  2. You usually can't print in mod_wsgi. Use the logging module instead. That's really what you want, and the debug toolbar will show you log statements in the page, so you don't even have to look at the file.

    你通常无法在mod_wsgi中打印。请改用日志记录模块。这真的是你想要的,调试工具栏会在页面中显示日志语句,所以你甚至不必查看文件。