views:

22

answers:

1

I have two django projects on the same machine. They are set up using the standard django/apache/mod_python configuration, basically:

<Location "/mysite">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
    PythonPath "['/path/to/project/parent'] + sys.path"
</Location>

where mysite varies for the two projects (in the Location directive, the DJANGO_SETTINGS_MODULE, and the django.root). The PythonPath also varies.

When only one of the two Location directives are in place, whichever site it is for works fine. Either configuration works alone.

When I have both Location directives (which refer to distinct url paths), I can only get to one site. I have location directives for "/portal" and "/apitest", and when I go to http://mydomain.com/apitest, I always get the code from "/portal" being served.

Is it possible to serve two django sites from the same host just by including multiple Location directives, or is it necessary to use VirtualHosts?

Thanks, David

+1  A: 

The docs seem to suggest that you probably need to set different PythonInterpreter values for each of your Location blocks. Does that fix the problem?

If you need to put two Django installations within the same VirtualHost (or in different VirtualHost blocks that share the same server name), you'll need to take a special precaution to ensure mod_python's cache doesn't mess things up. Use the PythonInterpreter directive to give different <Location> directives separate interpreters:

<VirtualHost *>
    ServerName www.example.com
    # ...
    <Location "/something">
        SetEnv DJANGO_SETTINGS_MODULE mysite.settings
        PythonInterpreter mysite
    </Location>

    <Location "/otherthing">
        SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings
        PythonInterpreter othersite
    </Location>
</VirtualHost>

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#multiple-django-installations-on-the-same-apacheBlockquoteBlockquotedirectives

Paul McMillan