django dynamically deduce SITE_ID according to the domain
- by dcrodjer
I am trying to develop a site which will render multiple customized sites according to the domain name (subdomain to be more precise). My all the domain names are redirected to the
So for each site there will be a corresponding model which defines how the site should look (SITE - SITE_SETTINGS)
What will be the best way to utilize the django sites framework to get the SITE_ID of the current site from the domain name instead of hard-coding it in the settings files (django sites documentation) and run database queries, render the views accordingly?
If using multiple settings file is my only option can this (wsgi script handle domain name) be done?
Update
So finally, following lukes answer, what I will do is define a custom middleware which makes the views available with the important vars required according to the domain. And as far as sitemaps and comments is concerned, I will have to customize sitemaps app and a custom sites model on which the other models of sites will be based. And since the comments system is based on the hard-coded sitemap ID I can use it just as is on the models (models will already be filtered according to the site based on my sites framework) though the permalink feature will have to be customized. So a lot of customization.
Please suggest if I am going wrong anywhere in this because I have to ensure that the features of the project are optimized.
Thanks!