本文整理汇总了Python中werkzeug.wrappers方法的典型用法代码示例。如果您正苦于以下问题:Python werkzeug.wrappers方法的具体用法?Python werkzeug.wrappers怎么用?Python werkzeug.wrappers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug
的用法示例。
在下文中一共展示了werkzeug.wrappers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: response
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import wrappers [as 别名]
def response(*, mimetype: str = None, template_file: str = None):
def response_inner(f):
# print("Wrapping in response {}".format(f.__name__), flush=True)
@wraps(f)
def view_method(*args, **kwargs):
response_val = f(*args, **kwargs)
if isinstance(response_val, werkzeug.wrappers.Response):
return response_val
if isinstance(response_val, flask.Response):
return response_val
if isinstance(response_val, dict):
model = dict(response_val)
else:
model = dict()
if template_file and not isinstance(response_val, dict):
raise Exception(
"Invalid return type {}, we expected a dict as the return value.".format(type(response_val)))
if template_file:
response_val = flask.render_template(template_file, **response_val)
resp = flask.make_response(response_val)
resp.model = model
if mimetype:
resp.mimetype = mimetype
return resp
return view_method
return response_inner
#
# def template(template_file: str = None):
# def template_inner(f):
# @wraps(f)
# def view_method(*args, **kwargs):
# data_dict = f(*args, **kwargs)
# if not isinstance(data_dict, dict):
# raise Exception(
# "Invalid return type {}, we expected a dict as the return value.".format(type(data_dict)))
#
# return flask.render_template(template_file, **data_dict)
#
# return view_method
#
# return template_inner
示例2: response
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import wrappers [as 别名]
def response(*, mimetype: str = None, template_file: str = None):
def response_inner(f):
# print("Wrapping in response {}".format(f.__name__), flush=True)
@wraps(f)
def view_method(*args, **kwargs):
response_val = f(*args, **kwargs)
if isinstance(response_val, werkzeug.wrappers.Response):
return response_val
if isinstance(response_val, flask.Response):
return response_val
if isinstance(response_val, dict):
model = dict(response_val)
else:
model = dict()
if template_file and not isinstance(response_val, dict):
raise Exception(
"Invalid return type {}, we expected a dict as the return value.".format(type(response_val)))
if template_file:
response_val = flask.render_template(template_file, **response_val)
resp = flask.make_response(response_val)
resp.model = model
if mimetype:
resp.mimetype = mimetype
return resp
return view_method
return response_inner
#
# def template(template_file: str = None):
# def template_inner(f):
# @wraps(f)
# def view_method(*args, **kwargs):
# data_dict = f(*args, **kwargs)
# if not isinstance(data_dict, dict):
# raise Exception(
# "Invalid return type {}, we expected a dict as the return value.".format(type(data_dict)))
#
# return flask.render_template(template_file, **data_dict)
#
# return view_method
#
# return template_inner