APIView 常规用法
from rest_framework.views import APIView
from .models import Category
from .serializers import CategorySerializer
from rest_framework.response import Response
class ListView(APIView):
def get(self, request):
categories = Category.objects.all()
serializer = CategorySerializer(categories, many=True)
return Response(serializer.data)
配置路由
urlpatterns = [
path('', views.ListView.as_view(), name='list'),
]
```...