本文整理匯總了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