Quantcast
Channel: Peter of the Norse Thinks He’s Smarter than You
Viewing all articles
Browse latest Browse all 54

Mixing Django and Other Content with Apache

$
0
0

My major Django project involves mixing Django urls with static. That is, I want /blog/ and /djpro/ to be handled by the same Python dæmon, but / to be the static file /html/index.html.

Turns out that’s not something you can do out of the box. mod_wsgi splits the url when you use WSGIScriptAlias and Django treats it as if you did an include in your URL. You can merge them together in your wsgi.py

from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()

# I found a thing at http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
# that merges the PATH_INFO & SCRIPT_NAME.
def application(environ, start_response):
    environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
    environ['SCRIPT_NAME'] = '/'
    return _application(environ, start_response)

Then, all you need is to do is use multiple WSGIScriptAliases on the same WSGIDaemonProcess.


Viewing all articles
Browse latest Browse all 54

Trending Articles