from rest_framework.views import APIView from rest_framework.response import Response from django.contrib.auth import authenticate from utils.JWTAuthentication_diy import get_token,MyJWTAuthentication # Create your views here. class UserView(APIView): #datail=True的时候,查询字符串携带pk def post(self,request): username = request.data.get('username') password = request.data.get('password') user = authenticate(username = username,password = password) if user is not None: token = get_token(user) return Response(token) else: return Response("登录失败") class UserShowView(APIView): #局部配置 authentication_classes = [MyJWTAuthentication] # permission_classes = [IsAuthenticated] def post(self,request): token = request.auth user = request.user print(token) print(user) # print(user["user_modules"]) return Response("认证成功")