I'm getting problems establishing wgsi with django. I am after this http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/ . Yet I'm still really confused regarding where you can place the .wsgi file and when I have to set the sys.path. I've attempted it both directly outdoors and within the web root and that i can't get almost anything to act as expected.

# /home/ben/public_html/django_test/testproject/apache/django.wsgi:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Relivant apache conf:

DocumentRoot "/home/ben/public_html/django_test/testproject/"
WSGIScriptAlias / "/home/ben/public_html/django_test/testproject/apache/django.wsgi"

Apache Logs Error (standard apache 500 page):

ImportError: Could not import settings 'testproject.settings' (Is it on sys.path? ...

I'm able to at get django to a minimum of throw a mistake of it's own applying this:

import os
import sys

path = '/home/ben/public_html/django_test/testproject'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

which led to this django error page:

ImportError at /admin/
No module named testproject.urls

I place the wsgi at same level than configurations.py, and appears such as this:

import os
import sys

sys.path.insert(0,os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]))


os.environ['DJANGO_SETTINGS_MODULE'] = 'yourprojectname.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

this is actually the apache conf file:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName www.yourprojectname.com
    Alias /media/ /home/diegueus9/workspace/yourprojectname/media/

    <Directory /home/diegueus9/workspace/yourprojectname/media/>
        Order deny,allow
        Allow from all
    </Directory>

    WSGIScriptReloading On
    WSGIDaemonProcess yourprojectname 
    WSGIProcessGroup yourprojectname
    WSGIApplicationGroup yourprojectname
    WSGIPassAuthorization On

    WSGIScriptAlias / /home/diegueus9/workspace/yourprojectname/yourfile.wsgi
    ErrorLog /var/log/apache2/yourprojectname-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    CustomLog /var/log/apache2/yourprojectname-access.log combined

</VirtualHost>

Here is a nice tutorial that demonstrates how to make use of mod_wsgi with Django and some other products that aren't associated with this.

As a fast fix you are able to, alongside adding this to sys.path:

path = '/home/ben/public_html/django_test/testproject'

include this:

path2 = '/home/ben/public_html/django_test'

You may also change Python path inside your Apache VirtualHost:

WSGIDaemonProcess [...] python-path=/home/ben/public_html/django_test

But it's also wise to review mod_wsgi paperwork and learn what Graham Dumpleton recommends there.