Description

the SITE_ID configuration is per settings.py .
given the settings.py is unique per django project then this contradicts the whole purpose of sites framework to serve multiple domains using same django project .

i found information elsewhere about defining multiple wsgi.py files for each domain .
meaning in directory where django's default wsgi.py exist should have domain1_wsgi.py and domain2_wsgi.py
and in http server configuration to define parallel wsgi instances per file .

this information looks crucial for sites to actually server its purpose but it is not included in documentation, unless i somehow haven't understood how it is supposed to work .

Change History (13)

Generally speaking, the intent is to have two (or more) settings modules with a different value for SITE_ID. You could then use first one on 20 servers and the second one on 10 other servers. This doesn't require a different wsgi module because the wsgi module takes the name of the settings module from the environment.

but how is this done ?
how can one project have several independent settings modules ?
this information is crucial and doesn't appear in documentation or provided as a link to other article .
even the comment you wrote is not understood from documentation, so your comment should appear in that documentation .

Apache handles environment variable in a way I'm unable to describe and tends to bite beginners and experienced people alike. That's why the docs suggest selecting the settings to use in the wsgi module when you're using Apache + mod_wsgi : ​https://docs.djangoproject.com/en/dev/topics/settings/#on-the-server-mod-wsgi — but that's really a workaround for a limitation of Apache, you simply set DJANGO_SETTINGS_MODULE on other application servers such as gunicorn or uwsgi.

quote "and select the one to use with the DJANGO_SETTINGS_MODULE environment variable"
at what stage and what method should this selection happen ?
should i write middleware that checks response.HOST value and change that parameter accordingly ?

and either case, why isn't this topic covered in documentation ?
for example there is a special section that describes configuring apache wsgi to install django, so why doesn't that section describe how configuration wsgi can allow defining DJANGO_SETTINGS_MODULE parameter (if that is possible ..)

but i suggest this information be added to documentation, referring developers to web server environment variables so they now where to begin .
it is also important to mention the need for multiple settings modules since without them the sites framework won't work .

in fact given that multiple settings modules are required, then this mean the sites framework can only serve a static predetermined domain configuration and do not scale if you intend to implement dynamic domains according to user preferences .

Depending on your Apache setup, SetEnvIf may or may not do the right thing. Sorry, this advice is rather unspecific, but you can find all the details in mod_wsgi's documentation.

There's no "best way" in general, it all depends on your setup. However I can guarantee that you can do all you need in your application server's configuration, or at worst in the wsgi module (eg. if you're using Apache + mod_wsgi, rather than gunicorn or uwsgi).

This is seriously turning into a support thread. The docs don't seem that bad to me. Of course, if you don't know what an environment variable is, you need to learn that first, but that's outside the scope of Django. The only concrete improvement I can imagine is to change the title "On the server (mod_wsgi)", because it's only relevant "if you're using mod_wsgi", not "on the server" in general.

i still believe that documentation is not sufficient .
i don't expect it to explain what environment variables are, but at least add this line :
"in order to serve multiple domains, then parallel multiple settings modules must be created .
creating multiple settings can be achieved using DJANGO_SETTINGS_MODULE environment variable which is best set using mod_wsgi ."