zoukankan      html  css  js  c++  java
  • DRF框架之视图子类简介

    所谓,视图子类就是继承自视图扩展类和GenericAPIView类的类。

    他们,帮我们将请求方法封装好了,我们只需要,使用视图继承这些子类即可使用其中的方法。

    1) CreateAPIView

    提供 post 方法

    继承自: GenericAPIView、CreateModelMixin

    2)ListAPIView

    提供 get 方法

    继承自:ListModelMixin、GenericAPIView

    3)RetrieveAPIView

    提供 get 方法

    继承自: RetrieveModelMixin、GenericAPIView

    4)DestoryAPIView

    提供 delete 方法

    继承自:DestoryModelMixin、GenericAPIView

    5)UpdateAPIView

    提供 put 和 patch 方法

    继承自:UpdateModelMixin、GenericAPIView

    6)RetrieveUpdateAPIView

    提供 get、put、patch方法

    继承自: RetrieveModelMixin、UpdateModelMixin、GenericAPIView

    7)RetrieveUpdateDestoryAPIView

    提供 get、put、patch、delete方法

    继承自:RetrieveModelMixin、UpdateModelMixin、DestoryModelMixin、GenericAPIView

    案例代码:

    # url(r'^books/(?P<pk>d+)/$', views.BookDetailView.as_view()),
    class BookDetailView(RetrieveAPIView, UpdateAPIView, DestroyAPIView):
        """查询、修改、删除指定图书信息"""
    
        # 指定查询集
        queryset = BookInfo.objects.all()
        # 指定序列化器
        serializer_class = BookInfoModelSerializer
    
    
    # url(r'^books/$', views.BookListView.as_view()),
    class BookListView(ListAPIView, CreateAPIView):
        """查询所有图书信息、新增图书信息"""
    
        # 指定查询集
        queryset = BookInfo.objects.all()
        # 指定序列化器
        serializer_class = BookInfoModelSerializer
    该花的钱要花,该吃的饭要吃。
  • 相关阅读:
    kbmMW RunInTransaction
    有感Delphi 2021路线图
    kbmMW 5.13.00 Scheduler不执行SynchronizedAfterRun
    Delphi 10.4.1的编译器bug终于修正了!
    OUI作者开源作品
    kali安装pwntools遇到的一些问题
    电子公文传输系统团队项目
    AI 学习框架
    Linux top命令的用法详细详解
    c# DateTime时间格式和JAVA时间戳格式相互转换
  • 原文地址:https://www.cnblogs.com/chao666/p/12284407.html
Copyright © 2011-2022 走看看