1、APIView
继承:本身
导包地址:from rest_framework.views import APIView
使用方法:需要自己请求方法
rest_framework 中的类视图

2、ModelViewSet
继承:本身
导包地址:from rest_framework.viewsets import ModelViewSet
使用方法:写入queryset 和 serializer_class
rest_framework 中的类视图

3、mixins
导报地址:from rest_framework import mixins
使用方法:mixins.CreateModelMixin:创建数据
ListModelMixin : 获取全部数据
RetrieveModelMixin:获取单个数据
UpdateModelMixin:跟新数据 (如果使用patch需要给kwargs[‘partial’] = True)
DestroyModelMixin:删除数据
GenericAPIView: 里面由他们的公共方法
rest_framework 中的类视图

rest_framework 中的类视图

相关文章:

  • 2021-11-10
  • 2021-08-13
  • 2021-12-18
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2022-01-13
  • 2021-09-08
相关资源
相似解决方案