Archive for March, 2009

Django, mod_python and virtualenv

Just quick note for myself and for people still using mod_python.

To use virtualenv with mod_python create file in your virtualenv bin directory (change the path to reflect your setup):

activate_this = '/home/django/'
execfile(activate_this, dict(__file__=activate_this))

from django.core.handlers.modpython import handler

In the apache conf file add your virtualenv bin directory to the PythonPath and set PythonHandler to myvirtualdjango (copy-and-paste from real server httpd.conf):


    <Location "/">
        SetHandler python-program
        PythonPath "['/home/django/', '/home/django/'] + sys.path"
        PythonHandler myvirtualdjango
        SetEnv DJANGO_SETTINGS_MODULE settings
        SetEnv PYTHON_EGG_CACHE /var/tmp/egg
        PythonInterpreter polyprog_ru