django-environ icon indicating copy to clipboard operation
django-environ copied to clipboard

What's the proper way to define and call a boolean var

Open macmichael01 opened this issue 2 years ago • 5 comments

In my .env file I have defined:

DEBUG=True

Should this be defined with 1,0, true,false, True,False, on,off?

In my settings file:

# I would like to call it this way
DEBUG = env.bool("DEBUG", default=False)
DEBUG = env("DEBUG", default=False)
# However, I am not able to get the above to work properly so I have been simply doing this:
DEBUG = os.getenv("DEBUG", "False") == "True"

macmichael01 avatar Sep 08 '22 22:09 macmichael01

why is this not documented?

technolingo avatar Apr 12 '23 19:04 technolingo

Any advice on the proper way here, please?

montaro avatar May 21 '23 20:05 montaro

Could any of you provide minimal reproducible example where the value from env file is not interpreted correctly?

According to the source code, following values should be interpreted as True:

true,on,ok,y,yes,1

They are all case insensitive

MateuszBelczowski avatar Jun 01 '23 10:06 MateuszBelczowski

This issue was from a while ago. I just re-tested using Django's runserver and it seems to be working fine. I'm trying to recall what the actual issue might have been. I think it might have been with a particular server environment that this was deployed too. I wish I had more details for you. It would be nice if those values were documented somewhere (if they aren't already documented). I'd say it's safe to close this out unless someone else ran into the issue I was experiencing.

macmichael01 avatar Jun 09 '23 19:06 macmichael01

Checked it and it's not documented. Dropping link to relevant code here for documentation. I guess adding it somewhere more prominently would be desirable. I'll do it when I get some time to fiddle with the code/docstrings/etc and add some other bits. Feel free anyone to beat me at it, thou :smile:.

pataquets avatar Apr 30 '24 16:04 pataquets