简体   繁体   English

如何多次使用同一django项目-每次使用不同的数据库?

[英]How to use same django project multiple times - each with diffrent database?

I wrote a django project that is some kind of a CMS. 我写了一个类似CMS的django项目。 Now, I want to be able to create several accounts that use that CMS, Each with a different database. 现在,我希望能够创建几个使用该CMS的帐户,每个帐户都有一个不同的数据库。 For example, user can create himself an account in my service - and he will get a site based of that CMS. 例如,用户可以在我的服务中为自己创建一个帐户-他将获得一个基于该CMS的网站。 How can I get started doing this? 我如何开始这样做?

Unfortunately Django is not suited to dynamically switch databases at runtime. 不幸的是,Django不适合在运行时动态切换数据库。 You either have to implement really hackish solutions (like mentioned in this question Django multiple and dynamic databases ) or to go with several independent Django instances which you will have to start up on your server dynamically. 您要么必须实现真正棘手的解决方案(如在此问题中提到的Django多个动态数据库 ),要么要与几个独立的Django实例一起使用,这些实例必须在服务器上动态启动。

A much simpler solution would be to stick to one database and distinguish different users' content by some other means, like Django Sites framework . 一种更简单的解决方案是坚持一个数据库,并通过其他方式(例如Django Sites framework)区分不同用户的内容。 The only problem with this approach in my opinion is that you will have to carefully set up your admin site configuration, so that users don't see each other's objects (in case you planned to use built-in Django admin). 我认为这种方法的唯一问题是,您必须仔细设置管理站点配置,以使用户看不到彼此的对象(以防您计划使用内置的Django admin)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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