Django + Apache + mod_wsgi = Bad Request (400)
Question: I'm trying to get my app launched on VPS in `Debug=True` mode.

I'm using Django 1.6 with Python 2.7.

I tried simple wscgi script and found that it works well (basically returns
200 and "Hello world" in text/plain) to the browser. Here's my configuration:

**virtual host config**

    
    
    <VirtualHost *:80>
    ServerName subdomain.domain.info
    ServerAlias www.subdomain.sigizmund.info
    WSGIScriptAlias / /var/www/subdomain/index.wsgi
    Alias /static/ /var/www/subdomain/static/
    ErrorLog /tmp/subdomain.error.log
    CustomLog /tmp/subdomain.custom.log common
    LogLevel debug
    <Location "/static/">
      Options -Indexes
    </Location>
    <Directory /home/sgzmd/code/myproject>
      Order deny,allow
      Allow from all
    </Directory>
    </VirtualHost>
    

**index.wsgi**

    
    
    import os
    import sys
    import site
    
    # Add the site-packages of the chosen virtualenv to work with
    site.addsitedir('/home/sgzmd/.virtualenvs/myenv/local/lib/python2.7/site-packages')
    
    PROJECT_PATH = '/home/sgzmd/code/myproject'
    if PROJECT_PATH not in sys.path:
        sys.path.insert(0, PROJECT_PATH)
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
    
    # Activate your virtual env
    activate_env=os.path.expanduser("~/.virtualenvs/myenv/bin/activate_this.py")
    execfile(activate_env, dict(__file__=activate_env))
    
    import django.core.handlers.wsgi
    import cStringIO
    
    import pprint
    
    class LoggingMiddleware:
    
        def __init__(self, application):
            self.__application = application
    
        def __call__(self, environ, start_response):
            errors = environ['wsgi.errors']
            pprint.pprint(('REQUEST', environ), stream=errors)
    
            def _start_response(status, headers, *args):
                pprint.pprint(('RESPONSE', status, headers), stream=errors)
                return start_response(status, headers, *args)
    
            return self.__application(environ, _start_response)
    
    application = LoggingMiddleware(django.core.handlers.wsgi.WSGIHandler())
    

I have following logging output: <http://pastebin.com/SnZVEeT1> (from
LoggingMiddleware) and `/var/log/django/error.log` while is being created and
re-created, remains completely empty.

I figured that the app is loading, by editing settings.py of my project, which
content is available here: <http://pastebin.com/Byr8RStb>

Would appreciate any pointers and ideas, as I'm basically out of options now.


Answer: This will not work for a start:

    
    
    activate_env=os.path.expanduser("~/.virtualenvs/myenv/bin/activate_this.py")
    

This is because Apache runs as a special user and ~ will not expand to your
own user where virtualenv was setup.

No idea if this is relevant or not though.

