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 myvirtualdjango.py in your virtualenv bin directory (change the path to reflect your setup):

#myvirtualdjango.py

activate_this = '/home/django/progopedia.ru/ve/bin/activate_this.py'
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):

<VirtualHost 127.0.0.1:81>
    ServerName progopedia.ru
    ServerAdmin admin@progopedia.ru

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