如何将我的自定义列表回复到请求方?

时间:2018-08-09 07:56:43

标签: python django django-rest-framework

如何在请求方回复我的自定义列表?

我使用django-rest-framework

class GetCustomListAPIView(APIView):
    permission_classes = [AllowAny]
    def get(self, request):

        list = [
            {
                "user": {"name": "David"},
                "passport": 123
            },
            {
                "user": {"name": "Den"},
                "passport": 124
            },
            {
                "user": {"name": "George"},
                "passport": 125
            },

        ]

        return Response() # what should I write in the Response for returning the list back to request side?

如何将列表返回到请求方?

1 个答案:

答案 0 :(得分:1)

由于使用的是DRF,因此可以传递到数据参数:

return Response(data=list, status=HTTP_200_OK)