Example #1
0
 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)
Example #2
0
 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)
Example #3
0
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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
 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)