[Answered ]-How to host 50 domains/sites with common Django code base

1👍

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.

1👍

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

0👍

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.

Leave a comment