继承ViewSetMixin的视图类
作者:互联网
from rest_framework.viewsets import ViewSetMixin class Book6View(ViewSetMixin,APIView): #一定要放在APIVIew前 def get_all_book(self,request): print("xxxx") book_list = Book.objects.all() book_ser = BookSerializer(book_list, many=True) return Response(book_ser.data) # urls.py #继承ViewSetMixin的视图类,路由可以改写成这样 path('books6/', views.Book6View.as_view(actions={'get': 'get_all_book'})),
标签:Book6View,get,ViewSetMixin,list,视图,继承,book 来源: https://www.cnblogs.com/dzs894330350/p/16104780.html