django-environ
django-environ copied to clipboard
What's the proper way to define and call a boolean var
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"
why is this not documented?
Any advice on the proper way here, please?
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
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.
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:.