Multi-tenant Django applications: altering database connection per request?

前端 未结 3 984
一整个雨季
一整个雨季 2020-12-23 02:20

I\'m looking for working code and ideas from others who have tried to build a multi-tenant Django application using database-level isolation.

Update/Solution

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 03:01

    For the record, I chose to implement a variation of my first idea: issue a USE in an early request middleware. I also set the CACHE prefix the same way.

    I'm using it on a small production site, looking up the tenant name from a Redis database based on the request host. So far, I'm quite happy with the results.

    I've turned it into a (hopefully resuable) github project here: https://github.com/mik3y/django-db-multitenant

提交回复
热议问题