title: Django + mod_wsgi. Set OS environment variable from Apache's SetEnv
body: <p>I need to split Django's development and production settings. I decided that if <code>USKOVTASK_PROD</code> variable is set, then app should use production settings. I read <a href="http://drumcoder.co.uk/blog/2010/nov/12/apache-environment-variables-and-mod_wsgi/">this</a> article and tried to do it.</p>
  
  <p>My snippets:</p>
  
  <p><strong>/etc/apache2/sites-enabled/uskovtask.conf:</strong></p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  
  ServerName uskovtask.*.com
  ServerAlias uskovtask.*.com
  DocumentRoot /mnt/ebs/uskovtask
  
  
  Alias /static /mnt/ebs/uskovtask/static/
  &lt;Directory /mnt/ebs/uskovtask/static&gt;
      Require all granted
  &lt;/Directory&gt;
  
  #WSGIPythonPath /mnt/ebs/uskovtask
  WSGIDaemonProcess uskovtask.*.com python-path=/mnt/ebs/uskovtask:/usr/lib/python2.7/site-packages
  WSGIProcessGroup uskovtask.*.com
  WSGIScriptAlias / /mnt/ebs/uskovtask/uskovtask/wsgi.py
  SetEnv USKOVTASK_PROD 1
  
  
  &lt;Directory /mnt/ebs/uskovtask/uskovtask&gt;
  &lt;Files wsgi.py&gt;
      Require all granted
  &lt;/Files&gt;
  &lt;/Directory&gt;
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong>wsgi.py:</strong></p>
  
  <pre><code>import os
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "uskovtask.settings")
  
  from django.core.wsgi import get_wsgi_application
  
  _application = get_wsgi_application()
  
  def application(environ, start_response):
      if 'USKOVTASK_PROD' in environ:
          os.environ.setdefault('USKOVTASK_PROD', environ['USKOVTASK_PROD'])
      return _application(environ, start_response)
  </code></pre>
  
  <p><strong>settings.py's part:</strong></p>
  
  <pre><code>import os
  
  if 'USKOVTASK_PROD' in os.environ:
      from settings_prod import *
  else:
      from settings_dev import *
  </code></pre>
  
  <p>But it always imports settings_dev's settings. Why?</p>