zoukankan      html  css  js  c++  java
  • DRF的View方法

    APIView

    APIView与Django的View类似,我们的业务类只需要继承APIView,在URL传递过程,我们只需要调用APIView的as_view()方法,然后URL就会调用业务类对应的HTTP方法,如get,post,put,delete(对应查 增 改 删)方法,我们在业务代码中只需要实现三个功能即可实现get方法

    ORM调用
    序列化
    返回数据

    CreateAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    提供post方法处理程序。

    ListAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于只读端点以表示模型实例的集合。
    提供get方法处理程序。

    RetrieveAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于表示单个模型实例的只读端点。
    提供get方法处理程序。

    DestroyAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于单个模型实例的仅删除端点。
    提供delete方法处理程序。

    UpdateAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于单个模型实例的仅更新端点。
    提供put和patch方法处理程序。

    ListCreateAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于读写端点以表示模型实例的集合。
    提供get和post方法处理程序。

    RetrieveUpdateAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于读取或更新端点以表示单个模型实例。
    提供get,put并且patch方法处理。

    RetrieveDestroyAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于读取或删除端点以表示单个模型实例。
    提供get和delete方法处理程序。

    RetrieveUpdateDestroyAPIView

    需要写字符查询集 与 序列化器
    queryset = models.xx..
    serializer_class = form seializer im.....
    用于读写 - 删除端点以表示单个模型实例。
    提供get,put,patch和delete方法处理。

  • 相关阅读:
    Grails批改默认启动端口
    基于注解的SpringMVC简单介绍
    JSP、Servlet中的相对路径和绝对路径
    jsp相对路径绝对路径
    idea如何设置注释作者信息
    alt+4 打开控制台
    idea常用快捷键
    解决Error running 'index.jsp : Address localhost:1099 is already in use的方法
    演示事物所需表
    关于jdbc的面试题
  • 原文地址:https://www.cnblogs.com/Gin1/p/14312649.html
Copyright © 2011-2022 走看看