def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) if serializer.is_valid(raise_exception=True): serializer.save() result = default_response() result['data'] = serializer.data return Response(result)
def put(self, request, pk, format=None): user = self.get_objects(pk) serializer = UserInfoSerializer(user, data=request.data) print(request.data) if serializer.is_valid(): serializer.save() result = default_response() result['data'] = serializer.data return Response(result) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def wxlogin_view(request, format=None): """ 小程序端微信登录 """ print(request.data) result = default_response() instance = wxlogin(request) if instance is None: result['data']['reseaion'] = "登录失败" return Response(result) jwt_token = create_jwt_token(instance.open_id) result['data']['JWT'] = jwt_token result['data']['user_id'] = instance.id return Response(result)
def get(self, request, format=None): category = Category.objects.all() serializer = CategorySerializer(category, many=True) result = default_response() result['data'] = serializer.data return Response(result)
def get(self, request, pk, format=None): product = self.get_objects(pk) serializer = ProductSerializer(product) result = default_response() result['data'] = serializer.data return Response(result)
def get(self, request, format=None): product = Product.objects.all() serializer = ProductSerializer(product, many=True) result = default_response() result['data'] = serializer.data return Response(result)
def get(self, request, pk, format=None): user = self.get_objects(pk) serializer = UserInfoSerializer(user) result = default_response() result['data'] = serializer.data return Response(result)