Consider a Django app built to serve multiple sites with slightly differing content using the standard Django sites
framework.
The traditional way to host this would be to configure multiple Site
objects and setup the app in multiple Django projects with each project pointing to a different SITE_ID
in their respective settings.py
:s.
For various reasons I'd like to avoid having to create a new project for each new site. I want to be able to setup one project and have Django figure out which Site
object to use based on the hostname referenced in the incoming HTTP request.
What is the recommended way to achieve this functionality?
Clarification: I want the site framework to ignore settings.SITE_ID
(which is hard-coded in settings.py
) and instead dynamically fetch Site objects based on what is in the Host
header. Why this requirement? I'll be adding and removing sites multiple times per hour and the total amount of sites will exceed 10,000, so setting up a Django project for each site is not an option. Is this a problem that is solvable in Django? If so, what is the best way to achieve it?