本文整理汇总了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
示例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