def get(self, request, *args, **kwargs): """ 用户登录请求 :param request: 登录信息 :return: 登录后的对象 """ username = request.query_params.get("username") password = request.query_params.get("password") user_obj = User.objects.filter(username=username, password=password).first() if user_obj: data = UserModelSerializer(user_obj).data return Response({ "results": data, "message": True }, status=status.HTTP_200_OK) return Response({ "results": "登录参数有误", "message": False }, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kwargs): data = request.data serializer = UserModelSerializer(data=data) serializer.is_valid(raise_exception=True) user_obj = serializer.save() return Response({"results": UserModelSerializer(user_obj).data})
def post(self, request, *args, **kwargs): data = request.data print(data) serializer = UserModelSerializer(data=data) serializer.is_valid(raise_exception=True) save = serializer.save() return Response({ 'result': UserModelSerializer(save).data, }, status=status.HTTP_201_CREATED)
def get(self, request, *args, **kwargs): username = request.GET.get('username') pwd = request.GET.get('password') rst = User.objects.filter(username=username, password=pwd).first() print(rst) if rst: data = UserModelSerializer(rst).data return Response({ 'result': data, 'message': True }, status=status.HTTP_200_OK) return Response({ 'result': "登录参数有误", 'message': False }, status=status.HTTP_400_BAD_REQUEST)