改写用户基本表
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
... AUTH_USER_MODEL = 'appjwt.User' ...
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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"
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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})