3

I have been researching the various (and there are many) ways to have multiple sites under a single Django framework.

I still don't see a solution that fits well for my use case. The use case being:

  • A single database, as the majority of data (95%+) will be shared between two apps
  • Two distinct user types, that each login via different domains, and in fact interact with the same raw data, differently

What I want to achieve is this:

When a visitor comes to example.com, the settings for SITE_ID = 1 are in effect.

When a visitor comes to training.example.com, the settings for SITE_ID = 2 are in effect.

I want to do this because:

  • I want to use explicitly different UserProfile objects for the different users
  • I want to mix and match views and apps at my will between the different domains

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.

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.

Then the server will in fact be serving two distinct wsgi apps, even though they use much of the same code.

So, in this scenario, my Django project will have:

  • example.com.settings.py (SITE_ID = 1)
  • training.example.com.settings.py (SITE_ID = 2)
  • example.com.wsgi.py (uses example.com.settings.py)
  • training.example.com.wsgi.py (uses training.example.com.settings.py)

My scenario here should work but it will be twice the memory of solving this within the same Django instance.

Any better implementation for what I need to achieve?

1 Answers1

-1

For what I know settings.py is unique for every django project, and the SITE_ID is defined at this level. IMHO the best approach is to use many django projects with database routers. In each project you can define the SITE_ID for use with the django sites framework. https://docs.djangoproject.com/en/dev/topics/db/multi-db/#database-routers

user1658078
  • 132
  • 5