开发者

How to approach implementation of mutiple-sites inside a django application?

Requirement: enable one instance of your Django application to serve multiple clients. By client we can mean different domains or different accounts that are not supposed to access each other's data.

The estimated number of clients, is around hundreds.

I'm sure that there are many, but I'm looking for the one what would minimize the effort in the long run. Two of them could be:

  1. One would be to use the sites framework in Django and one database and开发者_如何学Python add a site_id for most models (sounds scary)
  2. Usa one database for authentication and sites module and use the multi-database feature for keeping client specific models data in a separate database. This scares me too because I should implement dynamic database creation for new clients and worse, I do not know how to handle database migration when I upgrade the application.

What is your recommended approach for this?


If you can have multiple instances of the same application with a different SITE_ID for each site, then that would be the preferred option. That way you could either using a different database for each site, or reliably use the Django sites framework.

It is possible if you want a single process or a handful of processes to serve hundreds of sites, however it's bending the current design of Django. Using Site.objects.get_current() relies on SITE_ID, so you'll have to use something else to figure out the current site.

One package which offers the functionality you need is django-threaded-multihost, you can use get_current_host on a per request basis to get a different site.

The only downside would be that any Django apps which use Site.objects.get_current() will need modification with such a setup, making it difficult to use certain pluggable applications awkward to use - you'll either have to monkey patch them or stick with apps you've created yourself for threaded-multihost usage in mind.

So, it's possible, but it just isn't that great with Django at the moment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜