1

Is it OK to set the database name setting depending on subdomain for each request?

Something like this in a middleware:

from django.db import connection

company_name = ... # read the subdomain
connection.settings_dict['NAME'] = 'db_' + company_name
Onur Celebi
  • 333
  • 1
  • 3
  • 15

1 Answers1

1

I think it is not OK.

Are you trying to make a multi-tenant application? Look at this question:

See also the sites framework and multiple databases (specially routers, "Manually selecting a database" and "Exposing multiple databases in Django's admin interface".

Community
  • 1
  • 1
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153