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
    该花的钱要花,该吃的饭要吃。
  • 相关阅读:
    IOS 线程 +并发
    ios
    ios
    ios uitableviewcell动态计算高度
    ios 画圆环进度条
    ios -几种常见定时器
    ios 加载本地html css文件 ps:css和html必须在同一文件夹下面
    UISegmentedControl 分段器加载不同的viewcontroller
    iOS ----Pods-resources.sh Permission denied
    UIView的layout(布局)与draw(绘图)
  • 原文地址:https://www.cnblogs.com/chao666/p/12284407.html
Copyright © 2011-2022 走看看