use two different authentication backends for different types of users

This question already has an answer here:

  • Django Multiple Authentication Backends Based On Status 2 answers

  • django provides an AUTHENTICATION_BACKENDS setting which should do what you require.

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

    Ours looks like this ....

    AUTHENTICATION_BACKENDS = (
        'social_auth.backends.facebook.FacebookBackend',  # fb backend par social_auth
        'social_auth.backends.twitter.TwitterBackend',  # twitter backend par social_auth
        'backends.EmailAuthBackend',
        'backends.APIAuthBackend',
        'django.contrib.auth.backends.ModelBackend',
    )
    

    In out case, the backends.APIAuthBackend is where we check the supplied user auth token. You simply need to write your authentication code in the def authenticate method of that class which returns a user if the token exists.

    The django docs provides more info.

    https://docs.djangoproject.com/en/dev/topics/auth/customizing/#writing-an-authentication-backend

    链接地址: http://www.djcxy.com/p/33802.html

    上一篇: Django REST框架/ Django

    下一篇: 为不同类型的用户使用两个不同的身份验证后端