Basic Django WSGI Handler

Posted on in Programming

Django LogoCreating a basic Django WSGI handler is pretty straightforward. The Django docs version is OK, but it relies on your application being part of the PYTHONPATH.

This is what I do instead:

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

sys.stdout = sys.stderr
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
application = WSGIHandler()

This basic handler sets the path for us so that the application can be installed in a different environment without causing problems. It assumes that the WSGI handler is in the top level directory of your application (the same directory as your settings file). It also puts the application directory first in the list. This should have the effect of insuring that modules that come with your application are loaded instead of the system-wide version.

My Bookshelf

Reading Now

Other Stuff