views:

92

answers:

3

I have 50 different websites that use the same layout and code base, but mostly non-overlapping data (regional support sites, not link farm). Is there a way to have a single installation of the code and run all 50 at the same time?

When I have a bug to fix (or deploy new feature), I want to deploy ONE time + 1 restart and be done with it.

Also:

Code needs to know what domain the request is coming to so the appropriate data is displayed.

+1  A: 

The Sites framework comes to mind.

Apart from that we have Django running for multiple sites by symlinking Django to various docroots. Works like a charm, too.

Boldewyn
Using Apache on the front end? FastCGI or what? How many Threads?
Off Rhoden
nginx with FastCGI. 2-10 threads each with default to 5.
Boldewyn
+1  A: 

I can see two quite distinct ways to do this:

  1. Use one database and the sites framework. Every post/picture/whatever model is connected to a Site and you always filter on Site. This requires a separate settings file for every database.
  2. Use one database for each and every site. This allows different users for every site, but requires duplication of everything that is stored in the database. It also requires a separate settings file pointing to the correct database.

Either way, you do not duplicate any code, only data.

--

If you need to do site-specific, or post-specific changes to ie. a template, you should read up on how Django loads templates. It allows you to specify a list, ie ["story_%d.html", "story_site_%d.html", "story.html"] and django will look for the templates in that order.

knutin
A: 

I just ran into this and ended up using a custom middleware class that:

  1. Fetch the HTTP_HOST
  2. Clean the HTTP_HOST (remove www, ports, etc.)
  3. Look up domain in a Website table that's tied to each account.
  4. Set the account instance on the HTTPRequest object.

The throughout my view code I do lookups based on the account stored in the HTTPRequest objects.

Hope that helps someone in the future.

sdolan
Thanks. I'm doing something similar, only with a cache layer to reduce trips to the database. However, if the cache layer is set to use the database, probably better to just outright make the request, just like you are doing.
Off Rhoden