当前位置: 首页>>代码示例>>Python>>正文


Python HttpResponse._closable_objects方法代码示例

本文整理汇总了Python中django.http.response.HttpResponse._closable_objects方法的典型用法代码示例。如果您正苦于以下问题:Python HttpResponse._closable_objects方法的具体用法?Python HttpResponse._closable_objects怎么用?Python HttpResponse._closable_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.response.HttpResponse的用法示例。


在下文中一共展示了HttpResponse._closable_objects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_cache_response

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import _closable_objects [as 别名]
    def process_cache_response(self,
                               view_instance,
                               view_method,
                               request,
                               args,
                               kwargs):
        key = self.calculate_key(
            view_instance=view_instance,
            view_method=view_method,
            request=request,
            args=args,
            kwargs=kwargs
        )
        response = self.cache.get(key)
        if not response:
            response = view_method(view_instance, request, *args, **kwargs)
            response = view_instance.finalize_response(request, response, *args, **kwargs)
            response.render()  # should be rendered, before picklining while storing to cache

            if not response.status_code >= 400 or self.cache_errors:
                response_dict = (
                    response.rendered_content,
                    response.status_code,
                    response._headers
                )
                self.cache.set(key, response_dict, self.timeout)
        else:
            content, status, headers = response
            response = HttpResponse(content=content, status=status)
            response._headers = headers

        if not hasattr(response, '_closable_objects'):
            response._closable_objects = []

        return response
开发者ID:chibisov,项目名称:drf-extensions,代码行数:37,代码来源:decorators.py

示例2: process_cache_response

# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import _closable_objects [as 别名]
    def process_cache_response(self,
                               view_instance,
                               view_method,
                               request,
                               args,
                               kwargs):

        key = self.calculate_key(
            view_instance=view_instance,
            view_method=view_method,
            request=request,
            args=args,
            kwargs=kwargs
        )

        timeout = self.calculate_timeout(view_instance=view_instance)

        response_triple = self.cache.get(key)
        if not response_triple:
            # render response to create and cache the content byte string
            response = view_method(view_instance, request, *args, **kwargs)
            response = view_instance.finalize_response(request, response, *args, **kwargs)
            response.render()

            if not response.status_code >= 400 or self.cache_errors:
                response_triple = (
                    response.rendered_content,
                    response.status_code,
                    response._headers.copy()
                )
                self.cache.set(key, response_triple, timeout)
        else:
            # build smaller Django HttpResponse
            content, status, headers = response_triple
            response = HttpResponse(content=content, status=status)
            response._headers = headers

        if not hasattr(response, '_closable_objects'):
            response._closable_objects = []

        return response
开发者ID:chibisov,项目名称:drf-extensions,代码行数:43,代码来源:decorators.py


注:本文中的django.http.response.HttpResponse._closable_objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。