Django                
            認証バックエンド
        
        
            
    サーチ…
電子メール認証バックエンド
 Djangoのデフォルト認証は、 usernameとpasswordフィールドで動作しusername 。電子メール認証バックエンドは、 emailとpassword基づいてユーザーを認証しpassword 。 
from django.contrib.auth import get_user_model
class EmailBackend(object):
    """
    Custom Email Backend to perform authentication via email
    """
    def authenticate(self, username=None, password=None):
        user_model = get_user_model() 
        try:
            user = user_model.objects.get(email=username)
            if user.check_password(password): # check valid password
                return user # return user to be authenticated
        except user_model.DoesNotExist: # no matching user exists 
            return None 
    def get_user(self, user_id):
        user_model = get_user_model() 
        try:
            return user_model.objects.get(pk=user_id)
        except user_model.DoesNotExist:
            return None
この認証バックエンドをAUTHENTICATION_BACKENDS設定に追加します。 
# settings.py
AUTHENTICATION_BACKENDS = (
    'my_app.backends.EmailBackend', 
    ... 
    )
Modified text is an extract of the original Stack Overflow Documentation
        ライセンスを受けた CC BY-SA 3.0
        所属していない Stack Overflow