一登录就报:Manager isn't available; 'auth.User' has been swapped for 'users.UserProfile'
在settings.py中也添加了
AUTHENTICATION_BACKENDS = { 'users.views.UserBackend' }
views.py里面是:
from django.contrib.auth.backends import ModelBackend from django.db.models import Q from django.shortcuts import render # Create your views here. from .models import UserProfile class UserBackend(ModelBackend): def authenticate(self, request, username=None, password=None, **kwargs): try: user = UserProfile.objects.get(Q(username=username) | Q(phone=username)) if user.check_password(password): return user except Exception as e: return None