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


Python Response.has_header方法代码示例

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


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

示例1: process_conditional_request

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import has_header [as 别名]
    def process_conditional_request(self, view_instance, view_method, request, args, kwargs):
        if_modified_since = self.get_if_modified_since(request)
        res_last_modified = self.calculate_last_modified(
            view_instance=view_instance, view_method=view_method, request=request, args=args, kwargs=kwargs
        )

        if request.method in SAFE_METHODS and self.is_hasnt_been_modified(res_last_modified, if_modified_since):
            response = Response(status=status.HTTP_304_NOT_MODIFIED)
        else:
            response = view_method(view_instance, request, *args, **kwargs)

        if res_last_modified and not response.has_header("Last-Modified"):
            response["Last-Modified"] = http_date(res_last_modified)

        return response
开发者ID:pombredanne,项目名称:django-rest-framework-last-modified,代码行数:17,代码来源:decorators.py

示例2: process_conditional_request

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import has_header [as 别名]
    def process_conditional_request(self,
                                    view_instance,
                                    view_method,
                                    request,
                                    args,
                                    kwargs):
        etags, if_none_match, if_match = self.get_etags_and_matchers(request)
        res_etag = self.calculate_etag(
            view_instance=view_instance,
            view_method=view_method,
            request=request,
            args=args,
            kwargs=kwargs,
        )

        if self.is_if_none_match_failed(res_etag, etags, if_none_match):
            if request.method in SAFE_METHODS:
                response = Response(status=status.HTTP_304_NOT_MODIFIED)
            else:
                response = self._get_and_log_precondition_failed_response(
                    request=request)
        elif self.is_if_match_failed(res_etag, etags, if_match):
            response = self._get_and_log_precondition_failed_response(
                request=request)
        else:
            response = view_method(view_instance, request, *args, **kwargs)
            if self.rebuild_after_method_evaluation:
                res_etag = self.calculate_etag(
                    view_instance=view_instance,
                    view_method=view_method,
                    request=request,
                    args=args,
                    kwargs=kwargs,
                )

        if res_etag and not response.has_header('ETag'):
            response['ETag'] = quote_etag(res_etag)

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


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