DEV Community

Discussion on: Django Cheat Sheet: Keep Credentials Secure with Environment Variables

Collapse
 
jamestimmins profile image
James Timmins

Yeah, that's an unfortunate drawback of dotenv. There's a couple of things you can do.

  1. Explicitly check for a string value. DEBUG = (os.getenv("DEBUG") == 'true')
  2. Cast the val to a boolean DEBUG = bool(os.getenv("DEBUG")), and use an empty string to denote a false value DEBUG=''.
  3. Use a more fully-featured package like django-environ. There's slightly more configuration required, but if your project has multiple boolean settings it might be worth it. (I haven't actually used django-environ, but it looks pretty interesting so I may investigate).
Collapse
 
bhupesh profile image
Bhupesh Varshney 👾

thanks for this