如何在Django项目中有两个不同的管理站点? [英] How to have 2 different admin sites in a Django project?

查看:82
本文介绍了如何在Django项目中有两个不同的管理站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Django项目中有2个独立的管理网站。



单独的意思是 - 他们应该有单独的用户身份验证,他们应该管理不同的模型,并有不同的外观和URL。



我想做的是客户想要分开的部分来管理页面的CMS部分,并分开用作后台解决方案。



我想到在我的项目树中只是复制od django.contrib.auth应用程序,命名方式不同,并使用单独的 admin.site。 register()调用它们。这样我可以在其中的每一个可以使用其他模型,不同的外观等。我不知道如何解决用户身份验证问题(我应该有不同的用户能够登录到CMS然后进入BackOffice) 。/ />

以前有人这样做,可以给我一些提示吗?或者我打算做的只是设计错误?

解决方案

要在不同的AdminSites中注册模型,您只需要创建不同的django.contrib.admin.sites.AdminSite, a href =http://docs.djangoproject.com/en/1.8/ref/contrib/admin/#adminsite-objects =nofollow noreferrer>看到这个。



您将很乐意与两个不同的管理员站点管理不同的模型并具有不同的模板。
对于身份验证和权限,您应该能够使用内置django.contrib.auth与自定义权限一样(希望其他人能够在这里帮助更多)


I want to have 2 separate admin sites inside a Django project.

By separate I mean - they should have separate users authentication, they should administer different models, and have different looks and URLs.

The reason I want to do it is the customer wants separate section to administer the CMS part of the page, and separate to use as a 'back-office' solution.

I thought about just making a copy od django.contrib.auth appliaction in my project tree, naming it differently and using separate admin.site.register() calls for both of them. This way I can have other models available in each one of them, diffrent looks, etc. I don't know how to solve the user-authentication problem (I should have different user to be able to log into CMS then into the BackOffice).

Anyone happened to do this before and could give me some hint? Or what I plan to do is just wrong by design?

解决方案

To register models in different AdminSites you just need to create different instances of django.contrib.admin.sites.AdminSite, see this.

You will be good to go with two different admin sites managing different models and having different templates. For authentication and permissions you should be able to use the build-in django.contrib.auth as is with custom permissions (hope someone else will be able to help more here)

这篇关于如何在Django项目中有两个不同的管理站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆