如何在请求方回复我的自定义列表?
我使用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?
如何将列表返回到请求方?
答案 0 :(得分:1)
由于使用的是DRF,因此可以传递到数据参数:
return Response(data=list, status=HTTP_200_OK)