Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
macmichael01 opened this issue Sep 8, 2022 · 5 comments
Open

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

macmichael01 opened this issue Sep 8, 2022 · 5 comments

Comments

@macmichael01
Copy link

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"
@technolingo
Copy link

why is this not documented?

@montaro
Copy link

montaro commented May 21, 2023

Any advice on the proper way here, please?

@MateuszBelczowski
Copy link

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

@macmichael01
Copy link
Author

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.

@pataquets
Copy link

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 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants