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

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

问题描述

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



错误页面仍然是默认的 DEBUG 而不是模板中的404,403和500模板root。



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



任何提示或解决方案?

解决方案

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



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



只是为了检测环境变量是否存在,最简单,因此您不必担心类型转换或特定格式的配置



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



要禁用调试,请从环境中删除变量,而不是尝试输入cast ...它似乎更可靠和愚蠢的证明。 config:unset DEBUG


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.

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

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.

Any tips or solutions?

解决方案

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

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)

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 DEBUG设置未应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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