本文整理汇总了Python中werkzeug.Response.add_etag方法的典型用法代码示例。如果您正苦于以下问题:Python Response.add_etag方法的具体用法?Python Response.add_etag怎么用?Python Response.add_etag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Response
的用法示例。
在下文中一共展示了Response.add_etag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import add_etag [as 别名]
def __call__(self, environ, start_response):
local.application = self
request = MongoRequest(environ)
local.url_adapter = adapter = url_map.bind_to_environ(environ)
environ['mongo.db'] = self.db
environ['mongo.fs'] = self.fs
try:
endpoint, values = adapter.match()
handler = getattr(views, endpoint)
data = handler(request, **values)
# WSGI
if callable(data):
return data(environ, start_response)
data = safe_keys(data)
data['request'] = request
# Templates
template = self.env.get_template("%s.html" % endpoint)
response = Response()
response.content_type = "text/html"
response.add_etag()
# if DEBUG:
# response.make_conditional(request)
data['endpoint'] = endpoint
response.data = template.render(**data)
except HTTPException, e:
response = e
示例2: get_resource
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import add_etag [as 别名]
def get_resource(request, theme, file):
"""Returns a file from the theme."""
theme = get_theme(theme)
if theme is None:
raise NotFound()
f = theme.open_resource(file)
if f is None:
raise NotFound()
resp = Response(wrap_file(request.environ, f),
mimetype=mimetypes.guess_type(file)[0] or 'text/plain',
direct_passthrough=True)
resp.add_etag()
return resp.make_conditional(request)