I am working with django and virtualenvwrapper. My objective is to remove all sensitive information from the settings file per the 12Factor app suggestions (http://12factor.net) and ultimately deploy to heroku. When testing this locally, to achieve this, I have created a .env file with different variable values like SECRET_KEY. I went to my virtualenv directory and added the following line to the postactivate script:
source .env
Whenever I start my virtual env for a project aka workon project_name, the environment variables from .env are available if I echo from the terminal
$ echo $SECRET_KEY
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
However when I try to access those variables from python they are unavailable
>>> import os
>>> os.environ.get('SECRET_KEY')
>>>
What is the correct way for python to access the environment variables stored in a .env file?
.env file:
WEB_CONCURRENCY=2
SECRET_KEY='XXXXXXXXXXXX'
DEBUG=True