欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
相关标签: 视图