Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to setup django with unique settings.py per SITE_ID
    text
    copied!<p>I have been researching the various (and there are many) ways to have multiple sites under a single Django framework.</p> <p>I still don't see a solution that fits well for my use case. The use case being:</p> <ul> <li>A single database, as the majority of data (95%+) will be shared between two apps </li> <li>Two distinct user types, that each login via different domains, and in fact interact with the same raw data, differently</li> </ul> <p>What I want to achieve is this:</p> <p>When a visitor comes to example.com, the settings for SITE_ID = 1 are in effect.</p> <p>When a visitor comes to training.example.com, the settings for SITE_ID = 2 are in effect.</p> <p>I want to do this because:</p> <ul> <li>I want to use explicitly different UserProfile objects for the different users</li> <li>I want to mix and match views and apps at my will between the different domains</li> </ul> <p>Django docs on the Sites framework don't seem to help me, even though with this and some other articles around, I can see a few possibilities.</p> <p>My current thinking is to actually solve it using the wsgi server (uWSGI in my case), where I'd take Django's default wsgi.py, duplicate it, and each wsgi conf wiill have its own Django settings.py. </p> <p>Then the server will in fact be serving two distinct wsgi apps, even though they use much of the same code. </p> <p>So, in this scenario, my Django project will have:</p> <ul> <li>example.com.settings.py (SITE_ID = 1)</li> <li>training.example.com.settings.py (SITE_ID = 2)</li> <li>example.com.wsgi.py (uses example.com.settings.py)</li> <li>training.example.com.wsgi.py (uses training.example.com.settings.py)</li> </ul> <p>My scenario here should work but it will be twice the memory of solving this within the same Django instance.</p> <p>Any better implementation for what I need to achieve?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload