• 使用django的用户表进行登录管理


    改写用户基本表

    ...
    AUTH_USER_MODEL = 'appjwt.User'
    ...
    setting.py
    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"
    model.py
    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})
    views.py
  • 相关阅读:
    ES6-11学习笔记--深拷贝与浅拷贝
    ES6-11学习笔记--对象的扩展
    ES6-11学习笔记--箭头函数
    ES6-11学习笔记--扩展运算符与rest参数
    ES6-11学习笔记--函数的参数
    ES6-11学习笔记--数组的扩展
    ES6-11学习笔记--解构赋值
    ES6-11学习笔记--数组遍历
    班课2
    班课1
  • 原文地址:https://www.cnblogs.com/ppzhang/p/12259702.html
Copyright © 2020-2023  润新知