あなたはserializers.Serializerから継承シリアライザを作成するなど、最初のパラメータとしてデータを渡すことができます:
serializers.py
from rest_framework import serializers
class YourSerializer(serializers.Serializer):
"""Your data serializer, define your fields here."""
comments = serializers.IntegerField()
likes = serializers.IntegerField()
views.py
from rest_framework import views
from rest_framework.response import Response
from .serializers import YourSerializer
class YourView(views.APIView):
def get(self, request):
yourdata= [{"likes": 10, "comments": 0}, {"likes": 4, "comments": 23}]
results = YourSerializer(yourdata, many=True).data
return Response(results)
あなたは 'serializers.Serializer'を使うことができます... – zaidfazil