python - 当我从我的 Django 应用程序中将它们设置为 ‘print’ 时,它们会去哪里?

标签 python django

我在 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/

相关文章:

javascript - 如何测试django前端javascript

python - (Django) 如何让用户 FK 注册用户名而不是代码 (int)

python - 对列表的单个元素进行排序

django - 我应该在 'Server IP Whitelist' facebook 开发者控制台上放置哪个 IP 地址? (来自 Facebook 的 400 错误)

python - 将数字字符引用符号转换为 unicode 字符串

python - 如何使用 python-keybinder 获取剪贴板内容

django - Dockerfile 运行 python 命令不起作用

django - 何时以及为什么我应该在 Django 网络应用程序中从功能性 Selenium 测试切换到单元测试?

python - Flask url_for - 不正确的静态文件夹路径

python - 获取与 Windows 中的任务管理器相同的进程详细信息