本文整理汇总了Python中django.http.response.HttpResponse._headers方法的典型用法代码示例。如果您正苦于以下问题:Python HttpResponse._headers方法的具体用法?Python HttpResponse._headers怎么用?Python HttpResponse._headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.response.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse._headers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_cache_response
# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import _headers [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
示例2: process_cache_response
# 需要导入模块: from django.http.response import HttpResponse [as 别名]
# 或者: from django.http.response.HttpResponse import _headers [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