title: Python (django) environment variables
body: <p>I am working with django and virtualenvwrapper. My objective is to remove all sensitive information from the settings file per the 12Factor app suggestions (<a href="http://12factor.net" rel="nofollow">http://12factor.net</a>) 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:</p>
  
  <pre><code>source .env 
  </code></pre>
  
  <p>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</p>
  
  <pre><code>$ echo $SECRET_KEY
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  </code></pre>
  
  <p>However when I try to access those variables from python they are unavailable</p>
  
  <pre><code>&gt;&gt;&gt; import os
  &gt;&gt;&gt; os.environ.get('SECRET_KEY')
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>What is the correct way for python to access the environment variables stored in a .env file?</p>
  
  <p>.env file:</p>
  
  <pre><code>WEB_CONCURRENCY=2
  SECRET_KEY='XXXXXXXXXXXX'
  DEBUG=True
  </code></pre>