Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ignoring DEBUG value when I use os.environ, why?

Tags:

python

django

In my Django settings I have the following:

DEBUG = os.environ['DEBUG_VALUE']

Where DEBUG_VALUE = False

However, Django continues to show full error messages when I do this. If I manual add DEBUG = False it works and shows 500 error.

For some reason Django is ignoring it when I use the os.environ value.

I have confirmed DEBUG_VALUE is False but outputting to a file.

I have even tried:

DEBUG = bool(os.environ['DEBUG_VALUE'])

and still shows full errors.

like image 787
Glyn Jackson Avatar asked May 03 '15 15:05

Glyn Jackson


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.

What does OS environ get do?

environ in Python is a mapping object that represents the user's environmental variables. It returns a dictionary having user's environmental variable as key and their values as value.

What is OS environ in Django?

django-environ is the Python package that allows you to use Twelve-factor methodology to configure your Django application with environment variables.


1 Answers

The value of os.environ['DEBUG_VALUE'] is a string and bool('non empty string') == True.

You should do something similar to:

DEBUG = os.environ['DEBUG_VALUE'] == 'TRUE'
like image 61
aumo Avatar answered Sep 28 '22 02:09

aumo