Forums

Pointing domains to specific Django apps

I have domains pointing at specific webapps on PA, but am wondering if anyone has any ideas (or if it is even possible) to point domains at specific Django apps within the same Django project.

For example, If I have a webapp called www.mywebapp.com and within that project I have two applications called Restaurant and Hostel. In my project, both apps work independently and have no dependency upon each other.

I'd like to point www.myhostelwebsite.com to an app located at www.mywebapp.com/restaurant/ and point www.myrestaurantwebsite.com to an app located at www.mywebapp.com/hostel/

Is this possible or can I only point a domain at a project and not an app within a project?

Hmm. The only way I can think of to do this would be to hack the directories in your WSGI files for the different domains. Where you currently have this in both:

application = django.core.handlers.wsgi.WSGIHandler()

you would instead have

_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
    environ['SCRIPT_NAME'] = "/restaurant/" + environ['SCRIPT_NAME'] 
    return _application(environ, start_response)

...for the "restaurant" version something similar but with "hostel" in the appropriate place for the "hostel" one.

Caveat -- I haven't tried this. But I think it will work... If it doesn't, you could try again, but replace SCRIPT_NAME with PATH_INFO. Here's the reference for the WSGI protocol, which may help.

Awesome, thanks giles. I'll give this a shot and learn more about WSGI protocol if this doesn't pan out.