# ENV variables can never seem to be False

**URL:** <https://forum.djangoproject.com/t/env-variables-can-never-seem-to-be-false/24968>\
**Category:** Getting Started\
**Created:** [November 2, 2023, 6:44am UTC](https://forum.djangoproject.com/t/env-variables-can-never-seem-to-be-false/24968 "2023-11-02T06:44:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [November 2, 2023, 6:44am UTC](https://forum.djangoproject.com/t/env-variables-can-never-seem-to-be-false/24968/1 "2023-11-02T06:44:36Z")

</div>

In my .env file I have `HTML_DEBUG=True` but `os.environ['HTML_DEBUG']` is always **True** even if I have `HTML_DEBUG=False`  
I had to resort to `.lower() == "true"` in my config.

```auto
HTML_DEBUG = os.environ['HTML_DEBUG']
HTML_DEBUG = HTML_DEBUG.lower() == "true"

```

Why is HTML\_DEBUG being treated as a string ?

---

<div class="post-metadata">

**Author:** ![addwebsolution](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/addwebsolution/32/23762_2.png) [@addwebsolution](https://forum.djangoproject.com/u/addwebsolution)\
**Post date:** [November 2, 2023, 8:25am UTC](https://forum.djangoproject.com/t/env-variables-can-never-seem-to-be-false/24968/2 "2023-11-02T08:25:03Z")

</div>

When you parse variable from .env then it is in string form i.e

```auto
"True" or "False" instead of True or False

```

In order to use them, convert them in boolean.

---

<div class="post-metadata">

**Author:** ![AmanBothra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amanbothra/32/16802_2.png) [@AmanBothra](https://forum.djangoproject.com/u/AmanBothra)\
**Post date:** [November 3, 2023, 6:26am UTC](https://forum.djangoproject.com/t/env-variables-can-never-seem-to-be-false/24968/3 "2023-11-03T06:26:14Z")

</div>

You can try this

Define a variable in setting like this **DEBUG = env.bool(“DEBUG”)**

in .env file  
**DEBUG=True**

---

<div class="post-metadata">

**Author:** ![addwebsolution](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/addwebsolution/32/23762_2.png) [@addwebsolution](https://forum.djangoproject.com/u/addwebsolution)\
**Post date:** [November 3, 2023, 6:33am UTC](https://forum.djangoproject.com/t/env-variables-can-never-seem-to-be-false/24968/4 "2023-11-03T06:33:53Z")

</div>

Yes `env.bool(“DEBUG”)` can be used but in above code snippet `os.environ` is being used. In order to use `env.bool` an additional package needs to be installed which is `django-environ` and then in settings configure

```auto
import environ
env = environ.Env()

```

then it can be utilized.
