python - 检查 Pylons 应用程序中是否启用了调试

标签 python configuration pylons

我正在开发一个相当简单的 Pylons 0.9.7 应用程序。在代码中如何判断是否启用了调试?也就是说,我对 INI 文件中 [app:main] 下的 debug 设置的值感兴趣。更一般地说,如何在代码中访问其他值?

最佳答案

# tmp.py
print __debug__


$ python tmp.py
True
$ python -O tmp.py
False

我不确定这在 Pylons 中是否成立,因为我从未使用过它 - 但在“普通”命令行 Python 中,如果启用优化,则启用调试。 -O 标志指示 Python 打开优化。

事实上,这个片段来自 Pylons documentation :

    # Display error documents for 401, 403, 404 status codes (and
    # 500 when debug is disabled)
    if asbool(config['debug']):
        app = StatusCodeRedirect(app)
    else:
        app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

看起来 config['debug'] 就是您想要的。

关于python - 检查 Pylons 应用程序中是否启用了调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1350227/

相关文章:

c# - 从 C# 运行多个 python 脚本

用于列出已执行测试的 PHPUnit 配置选项

CSS 未加载到 point_of_sale OpenERP 8

python - 使用 Pylons 和 SQLalchemy 在 sqlite 中存储 UUID

Sqlalchemy : association table for many-to-many relationship between groups and members. 如何删除关系?

python - 使用 Pyparsing 生成 Sql 到 Pymongo

python - 如何为 keras 中的 LSTM 回归准备输入数据?

Codeigniter nginx 404 错误

python - Pylons 和 AuthKit OpenID 问题

python - 像这样向 pandas 数据框添加一行有什么问题吗?