Integrating with Legacy Web Applications

It’s possible to run a Django application on the same Web server as an application powered by another technology. The most straightforward way of doing this is to use Apache’s configuration file, httpd.conf, to delegate different URL patterns to different technologies.

The key is that Django will be activated for a particular URL pattern only if your httpd.conf file says so. The default deployment explained earlier assumes you want Django to power every page on a particular domain:

<Location “/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
</Location>

Here, the <Location “/”> line means “handle every URL, starting at the root,” with Django. It’s perfectly fine to limit this <Location> directive to a certain directory tree. For example, say you have a legacy PHP application that powers most pages on a domain and you want to install a Django admin site at /admin/ without disrupting the PHP code. To do this, just set the <Location> directive to /admin/:

<Location “/admin/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
</Location>

With this in place, only the URLs that start with /admin/ will activate Django. Any other page will use whatever infrastructure already existed.

Note that attaching Django to a qualified URL (such as /admin/ in this section’s example) does not affect the Django URL parsing. Django works with the absolute URL (e.g., /admin/people/person/add/), not a “stripped” version of the URL (e.g., /people/person/add/). This means that your root URLconf should include the leading /admin/.

Back to Tutorial

Integrating with an Authentication System
Virtual Hosting and Tomcat

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?