Login or Sign up

typical wsgi script for django project with some path hacking

Posted by: skyl on Oct. 11, 2009

Here is a simple wsgi script. I just did some path hacking to it that some might consider fragile. But, it was a quick fix to make the file portable across servers.

import os
import sys

from os.path import abspath, dirname, join
sys.path.insert(0, abspath( dirname(__file__) ) )
sys.path.insert(0, abspath( join(dirname(__file__), 'myproject' ) ) ),
# the above two lines replace the hard-coded:
# sys.path = ['/path/to/wsgi', '/path/to/wsgi/myproject'] +\
# sys.path
from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
application = WSGIHandler()

Since the script is in my version control, it maintains the same location relative to my settings file regardless of the server that it is on.

Comments on This Post:

Please Login (or Sign Up) to leave a comment