• APIView和View的区别


    APIView和View的区别

      API继承了View

      重写了as_view方法

        --豁免csrf

      def dispatch(self, request, *args, **kwargs):

        self.args = args

        self.kwargs = kwargs

        # 重新封装request

        # 新的request变成Request的实例化对象

        # 旧的request变成了_request

        request = self.initialize_request(request, *args, **kwargs)

        self.request = request

      def initialize_request(self, request, *args, **kwargs):

        parser_context = self.get_parser_context(request)

        return Request(

          request,

          parsers = self.get_parsers(),

          authenticators = self.get_authenticators(),

          negotiator = self.get_content_negotiator(),

          parser_context = parser_context

        )

      class Request(object):

        self._request = 旧的request

        def query_params(self):

          return self._request.GET

        def data(self):

          return post请求的数据

  • 相关阅读:
    20191024-1 每周例行报告
    20191017-1 每周例行报告
    20191010-2 每周例行报告
    梁梦瑶 20190919-4 单元测试
    交换机配置VLAN Cisco packet
    20191128-1 总结
    20191121-1 每周例行报告
    20191114-1 每周例行报告
    对组内成员的感谢博客
    每周例行报告
  • 原文地址:https://www.cnblogs.com/wjs521/p/9969283.html
Copyright © 2020-2023  润新知