简体   繁体   中英

multi-tenancy solution with django

I want to create a multi-tenant application where each tenant will have its own domain and database.

Domains will be like this: store1.saas.com, store2.saas.com .. and their respective databases will be store1 and store 2..

I have decided to name it as such so that depending upon on the url, i can set the database with some middleware.

I have tried https://github.com/bernardopires/django-tenant-schemas this but it wont work as it specifically asks to create a model inheriting from TenantMixin, which then is defined in settings like this. TENANT_MODEL = 'catalogue.Product' . I have multiple TenantModels and this scheme wont allow multiple models (it takes string and then uses split by "." and does their stuff based on it).

Trouble with me is

  1. how to create sub-domains
  2. how to test them in local, like store1.127.0.0.1:8000 wont work?

You could try emulating the future real world as close as possible by editing your hosts file /etc/hosts and putting in there:

127.0.0.1 store1.saas.com
127.0.0.1 store2.saas.com
... etc

Then you can navigate to your localhost by store1.saas.com and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM