Django Multiple Authentication Backend for one project, HOW?

后端 未结 4 1836
野性不改
野性不改 2020-12-05 00:52

Need serious help here.

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

4条回答
  •  失恋的感觉
    2020-12-05 01:43

    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',
        )
    

    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.

    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.

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

提交回复
热议问题