views:

105

answers:

1

Typically I've been lucky enough to have a fairly simple Django and Apache configuration.

But now I'm writing several apps that will sit on the same server and I need them to each have individual domains.

The apps live at www.myserver.com/app/app1 (app2...) and I would like to access it using www.someawesomedomain.com. I don't want a redirect since I do not want to expose the underlying path.

What is the best way to do this, in the context of 5 - 10 sites?

I'm using Apache2.

A: 

Your best bet here is probably a unique settings.py and urls.py file for each domain.

You would have a main settings file that has all your common settings in, then a per-site settings file that imports everything from the common one and overides the ROOT_URLCONF setting.

You can lay out your settings something like this:

- configs
-- settings.py
-- site1
--- settings.py
--- urls.py
-- site2
--- settings.py
--- urls.py
...

Then in each of your site settings files you would do something like:

from projectname.configs.settings import *

ROOT_URLCONF = 'projectname.configs.site1.urls'

Assuming you're using mod_wsgi on apache then you would do something like this in each wsgi file, pointing at the relevant settings module for that site

os.environ["DJANGO_SETTINGS_MODULE"] = "projectname.configs.site1.settings"

This approach also lets you take advantage of the django sites framework quite easily, by specifying a unque SITE_ID in each settings file.

The only real trick to getting this right is knowing how to manage the Python path so all the imports work. If you don't like having to manually create lots of files (5-10 sites is probably fine, but lots more would be annoying) then you could write a management command to generate all the files.

Garethr