Forums

Path variable in WSGI returns ImportError

My settings.py was located at '/home/<username>/<dir1>/<dir2>/<dir3>/settings.py', and I think I'm having a path problem. How should I name my path variable and os.environ['DJANGO_SETTINGS_MODULE'] variable?

This is what I was doing:

# TURN ON THE VIRTUAL ENVIRONMENT FOR YOUR APP
activate_this = '/home/<username>/.virtualenvs/rango/bin/activate_this.py'

import os
import sys

# My django settings file is at '/home/<username>/<dir1>/<dir2>/<dir3>/settings.py'
path = '/home/<username>/<dir1>/<dir2>/'

if path not in sys.path:
    sys.path.append(path)

os.chdir(path)

# TELL DJANGO WHERE YOUR SETTINGS MODULE IS LOCATED
os.environ['DJANGO_SETTINGS_MODULE'] = '<dir3>.settings'

# IMPORT THE DJANGO WSGI HANDLER TO TAKE CARE OF REQUESTS
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

:::python

Note that <dir2> and <dir3> have the same name, and I have setup the variable to activate the virtualenv beforehand.

This is what the log said: ImportError: Could not import settings '<dir3>.settings' (Is it on sys.path?): No module named <dir3>.settings

That all looks OK to me. But you're missing the actual line that executes virtualenv activation:

execfile(activate_this, dict(__file__=activate_this))