Django的多重认证后端的一个项目,怎么样? [英] Django Multiple Authentication Backend for one project, HOW?

查看:311
本文介绍了Django的多重认证后端的一个项目,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里需要严重的帮助。

Need serious help here.

我已经写在Django / Python的应用程序,我有把它扩大,包括一些其他的解决方案,在这个应用程序中的应用程序。
例如被整合我的应用程序被命名为my_new_app
现在有主应用程序编写的后端验证,我无法使用它。
我有一个MySQL数据库的查询和主应用程序使用cassendra和Redis的居多。
所以我的问题是,有没有什么办法,我可以使用一个单独的认证后端为新的应用程序my_new_app和运行都在同一个域中?
问题可能不那么清楚,我会澄清,如果问。

I have an application written in django/python and I have to extend it and include some other solution as an "app" in this application. For example my app to be integrated is named "my_new_app" Now there is a backend authentication written for the main application and i cannot use it. I have a mysql db to query from and the main app uses cassendra and redis mostly. So my question is, is there any way i can use a separate authentication backend for the new app "my_new_app" and run the both in the same domain? Question may not be that clear, i'll clarify if asked.

推荐答案

您的可以的有多个认证后端。只需设置 AUTHENTICATION_BACKENDS settings.py Django项目列出您要使用的后端实现。比如我经常使用的OpenID认证和标准的Django认证结合起来,这样在我的 settings.py

You can have multiple authentication backends. Just set the AUTHENTICATION_BACKENDS in settings.py of your Django project to list the backend implementations you want to use. For example I often use a combination of OpenID authentication and the standard Django authentication, like this in my settings.py:

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django_openid_auth.auth.OpenIDBackend',
    )

在这个例子中Django会首先尝试使用 django.contrib.auth.backends.ModelBackend ,这是Django的默认后台进行身份验证。如果失败,则它移动到下一个后端, django_openid_auth.auth.OpenIDBackend

In this example Django will first try to authenticate using django.contrib.auth.backends.ModelBackend, which is the default backend of Django. If that fails, then it moves on to the next backend, django_openid_auth.auth.OpenIDBackend.

请注意您的自定义后端必须在Django在可见的路径。在这个例子中,我要补充 django_openid_auth INSTALLED_APPS ,否则Django会无法导入它,使用它作为后端。

Note that your custom backends must be at a path visible by Django. In this example I have to add django_openid_auth to INSTALLED_APPS, otherwise Django won't be able to import it and use it as a backend.

另请阅读相关文件,这是非常写得很好,很容易理解:
<一href=\"https://docs.djangoproject.com/en/dev/topics/auth/customizing/\">https://docs.djangoproject.com/en/dev/topics/auth/customizing/

Also read the relevant documentation, it's very nicely written, easy to understand: https://docs.djangoproject.com/en/dev/topics/auth/customizing/

这篇关于Django的多重认证后端的一个项目,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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