restframework之视图
程序员文章站
2022-03-17 11:09:26
...
视图:
视图函数继承表
|->mixins.CreateModelMixin, POST创建
|->mixins.RetrieveModelMixin, Retrieve(get)显示单条
ModelViewSet |->mixins.UpdateModelMixin, put,patch更新
|->mixins.DestroyModelMixin, destory 删除
|->mixins.ListModelMixin, list(get) 查询所有
| |->ViewSetMixin
|->GenericViewSet |
|->generics.GenericAPIView|->views.APIView|->View
自定义视图
from rest_framework.viewsets import ModelViewSet
from rest_framework.pagination import PageNumberPagination
class xxx(ModelViewSet):
#查询结果集
queryset = models.XXX.objects.all()
#序列化的类
serializer_class = xxxxx
#分页的类
pagination_class = PageNumberPagination
上一篇: python - 高阶函数的概念