我在 Linux 服务器上有一个 Django 应用程序。在其中一个 View 中,执行了某种形式的 print
命令,并打印了一些字符串。我怎样才能找出打印的字符串是什么?是否有一些日志记录了这些东西?
最佳答案
输出应该在终端中,也就是 django 启动的地方。 (如果不直接启动,我不相信有办法读取)
正如linkedlinked指出的那样,最好不要使用print
,因为这会导致异常!但这不是唯一的原因:有一些模块(如 logging )是为此目的而制作的,而且它们有更多的选择。
This site (即使是从 2008 年开始)确认我的陈述:
If you want to know what’s going on inside a view, the quickest way is to drop in a print statement. The development server outputs any print statements directly to the terminal; it’s the server-side alternative to a JavaScript alert().
If you want to be a bit more sophisticated with your logging, it’s worth turning to Python’s logging module (part of the standard library). You can configure it in your settings.py: here he describes, what to do (look on the site)
出于调试目的,您还可以启用 debug-mode或使用 django-debug-toolbar .
希望对您有所帮助! :)
关于python - 当我从我的 Django 应用程序中将它们设置为 ‘print’ 时,它们会去哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3182298/