如何在 django 支持的站点中使用 2 个不同的身份验证?

发布于 2024-09-26 21:24:58 字数 447 浏览 1 评论 0原文

我目前管理一个用 django 编码的网站,有 2 个标准区域 - 前端和后台(使用 django 的管理界面构建)。

最近,客户声称他想要两种不同的身份验证 - 一种用于前端用户,另一种用于管理后台的人员。

到目前为止,它们都使用标准的 django.contrib.auth 身份验证。

我知道我可以让客户只使用不同的用户(也许,禁止“后台”用户登录前端部分)但是 - 他们想要更多的改变,例如:管理端的会话不活动缩短到几分钟(在前端 - 永远保持它)。

是否可以定义 django 站点的某些部分以使用不同的身份验证?使用不同的cookie等?

或者我应该为后台使用不同的域,例如在 site.com 上有一个前端,在 admin.site.com 上有一个管理员,然后将两者作为 2 个不同的应用程序运行、使用不同的 cookie 设置等?

I currently manage a website, coded in django, that has 2 standard areas - the frontend and backoffice (which is built using django's admin interface).

Recently the customer claimed he wanted 2 diffrent authentications - one for frontend users and another one - for people managing the backoffice.

Until now they both used standard django.contrib.auth authentication.

I know I could make the customer to just use diffrent users (and, maybe, disallow the "backoffice" users to log into the frontend part) but - they want more changes, like: session inactivity on the admin side shortened to few minutes (while on the frontend - to keep it like forever).

Is it possible to define parts of django site to use diffrent authentication? With diffrent cookies, etc?

Or should I use a diffrent domain for backoffice, like to have a frontend on site.com and admin on admin.site.com, then have both run as 2 diffrent applications, using diffrent settings for cookies, etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光的暖冬 2024-10-03 21:24:58

Django 提供了后端身份验证接口: http://docs.djangoproject.com /en/dev/topics/auth/#authentication-backends

在这里,您可以指定用户如何进行身份验证。您可以使用本地 login() 方法来验证后台用户的身份,并且您可以根据需要实现前端所需的任何其他内容。无论哪种方式,这都是您定义该功能的地方。

Django provides a backend authentication interface: http://docs.djangoproject.com/en/dev/topics/auth/#authentication-backends

Here, you can specify how you want the user to authenticate. You can use the local login() methods to authenticate the backoffice users, and whatever else you need for front end you can implement as needed. Either way, this is the place where you define that functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文