Question: I'm setting up Django using `os.getenv` to prepare it for deploying using Docker but it seems it is not reading the `.env` file. Any idea why is not reading it?

Here is the setup:

`.env`

```
SECRET_KEY=foo
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1

```

`settings.py` abstraction

```
import os
from pathlib import Path

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG = os.getenv('DEBUG')
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS')

```

Answer: 
You can use [python-decouple](https://pypi.org/project/python-decouple/) to get the environment variable stored in the root of your project in a .env file.

```
from decouple import config

SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', default=False, cast=bool)
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)

```

Note: for changes to apply you need to restart the server.
To get environment variables from docker or from the AWS Elastic Beanstalk i use
`os.environ.get('SECRET_KEY')`, this is generally more reliable than `os.environ['SECRET_KEY']`