Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Django DEBUG Setting not applied

Tags:

django

heroku

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?

like image 414
Murph Avatar asked Apr 28 '13 00:04

Murph


People also ask

How do I enable debug mode in Django?

The debug mode (DEBUG=True) is turned on by default in the Django framework. It provides a detailed traceback with the local variables to find out the error with the line numbers. The error can be triggered from the view page by setting the value of assert to False in the view file.

How do I disable debug in Django?

To disable debug mode, set DEBUG = False in your Django settings file.


2 Answers

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

like image 71
Yuji 'Tomita' Tomita Avatar answered Oct 22 '22 04:10

Yuji 'Tomita' Tomita


The problem is that the environment variable is not a boolean, rather a string. So do place below line in settings.py

DEBUG = (os.environ.get('DEBUG_VALUE') == 'True')

like image 24
kvothe__ Avatar answered Oct 22 '22 05:10

kvothe__