未应用 Heroku Django 调试设置 [英] Heroku Django DEBUG Setting not applied

查看:15
本文介绍了未应用 Heroku Django 调试设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 Heroku 上有一个正在运行的生产 Django 应用程序.不幸的是,我无法关闭 Heroku 上的 DEBUG 设置.在本地关闭它可以正常工作,但是当推送到 Heroku 时(在 heroku config:set DEBUG=False 之后),它不适用.

I currently have a running production Django application on Heroku. Unfortunately, I haven't been able to turn off the DEBUG setting on Heroku. Turning it off locally works fine, but when pushed to Heroku (after heroku config:set DEBUG=False), it doesn't apply.

错误页面仍然是默认的 DEBUG 页面,而不是我们模板根目录中的 404、403 和 500 模板.

The error pages are still the default DEBUG ones instead of the 404, 403, and 500 templates in our template root.

我还尝试使用 DJANGO_DEBUG 设置,以防与 DEBUG 有任何环境冲突,并将结果转换为设置文件中的布尔值.heroku config 显示环境中的设置是正确的.这是在 Django 1.3、Heroku Cedar 上.

I have also tried using a DJANGO_DEBUG setting in case there were any environment conflicts with DEBUG, and casting the result to a boolean in the settings file. heroku config shows the settings in the environment are correct. This is on Django 1.3, Heroku Cedar.

任何提示或解决方案?

推荐答案

你的 django settings.py 文件是否甚至在环境中查找?

Does your django settings.py file even look in the environment?

默认情况下,它不关心您在环境中设置的任何内容(通过config:set").如果您将环境转换"为布尔值,请确保正确转换.bool('False') 仍然是 True.

It does not, by default, care about anything you've set in the environment (via "config:set"). If you're "casting" the environment to a boolean, make sure you're casting it correctly. bool('False') is still True.

最简单的方法是检测环境变量是否存在,这样您就不必担心类型转换或配置的特定格式.

It's simplest just to detect if the environment variable exists so you don't have to worry about type casting or specific formats of the configuration.

DEBUG = os.environ.get('DEBUG', False)

要禁用调试,请从环境中删除变量,而不是尝试进行类型转换……它似乎更可靠和万无一失.config:unset DEBUG

To disable debug, remove the variable from the environment instead of trying to type cast... it just seems much more reliable and fool proof. config:unset DEBUG

这篇关于未应用 Heroku Django 调试设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆