使用django的用户表进行登录管理
改写用户基本表
... AUTH_USER_MODEL = 'appjwt.User' ...
from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. class User(AbstractUser): mobel = models.CharField(max_length=32,null=True) class Meta: db_table = "mm_user"
from django.shortcuts import render from rest_framework.views import APIView from rest_framework.response import Response from appjwt.models import User from django.contrib.auth.hashers import check_password,make_password from django.contrib.auth import authenticate from appjwt.models import User from appjwt.serializer import UserSerializer # Create your views here. class UserView(APIView): #祖册 def post(self,request): data = request.data print(data) password_hash = make_password(data["pwd"]) try: user = User.objects.create(username=data["username"],password=password_hash,mobel=data['mobel']) return Response({"code":200}) except: return Response({"code": 500}) #验证 def get(self,request): data = request.data print(data) users = authenticate(username=data["username"],password=data["pwd"]) print(users) if users: return Response({"code": 200}) else: return Response({"code":500})