Esempio n. 1
0
    def hello(self, request, format=None):
        """
        返回
        --------------------

        成功返回示例:
        --------------------

            [
             
            ]

        错误返回:
        ------------

            =======================  ===========================
                error_key                   response
            =======================  ===========================
                code_invalid              代码输入有误
            =======================  ===========================

        code -- 代码
        test -- 测试位
        """
        serializer = ContactDataSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 2
0
    def post(self, request, format=None):
        serializer = ContactDataSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 3
0
    def get_test(self, request, pk=None):
        """
        返回
        --------------------

        成功返回示例:
        --------------------

            [
              
            ]

        错误返回:
        ------------

            =======================  ===========================
                error_key                   response
            =======================  ===========================
                code_invalid               代码输入有误
            =======================  ===========================

        code -- 代码
        """
        print(request.user)
        print(request.data)
        contacts = Contact.objects.all()
        serializer = ContactDataSerializer(contacts, many=True)
        return Response(serializer.data)
 def get(self, request, format=None):
     contacts = Contact.objects.all()
     serializer = ContactDataSerializer(contacts, many=True)
     return Response(serializer.data)