Django uses custom authentication
Django creates a login application using custom authentication
First, create a new login app to store the authentication code.
python manage.py startapp login
Modify the authentication items in settings. py
AUTHENTICATION_BACKENDS = ( 'login.auth.UsernamePasswordAuth',)
Custom Authentication
Create the auth. py file in the login app. The content is as follows:
#coding:utf-8from django.contrib.auth.models import Userclass UsernamePasswordAuth(object): def authenticate(self, username=None, password=None): print("UsernamePasswordAuth.authenticate") try: user = User.objects.get(username__iexact=username) if user.check_password(password): return user except User.DoesNotExist: return None def get_user(self, user_id): print("UsernamePasswordAuth.get_user") try: user = User.objects.get(pk=user_id) return user except User.DoesNotExist: return None