1. 9个视图子类
from rest_framework.generics import ListAPIView, CreateAPIView, ListCreateAPIView
from rest_framework.generics import RetrieveAPIView, DestroyAPIView, UpdateAPIView
from rest_framework.generics import RetrieveUpdateDestroyAPIView, RetrieveDestroyAPIView, RetrieveUpdateAPIView
# 以后想写5个接口中的某一个或某几个或所有,只需要选择继承不同的类即可,类中只需要配置两个类属性
queryset = Publish.objects.all()
serializer_class = PublishSerializer
1.1 视图类
1 . 想写 publish: 查询所有,查询单条,修改一条,新增一条,删除一条的接口⛵
class PublishView(ListCreateAPIView):
queryset = Publish.objects.all()
serializer_class = PublishSerializer
class PublishDetailView(RetrieveUpdateDestroyAPIView):
queryset = Publish.objects.all()
serializer_class = PublishSerializer
2 . 想写 publish: 查询单条,新增一条,的接口--->使用9个视图子类编写 标签:get,ViewSetMixin,子类,self,list,视图,class,serializer From: https://www.cnblogs.com/huangchunfang/p/17680681.html