本文整理汇总了Python中werkzeug.wrappers.BaseResponse.headers['Access-Control-Allow-Origin']方法的典型用法代码示例。如果您正苦于以下问题:Python BaseResponse.headers['Access-Control-Allow-Origin']方法的具体用法?Python BaseResponse.headers['Access-Control-Allow-Origin']怎么用?Python BaseResponse.headers['Access-Control-Allow-Origin']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.wrappers.BaseResponse
的用法示例。
在下文中一共展示了BaseResponse.headers['Access-Control-Allow-Origin']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __common_resp_handle
# 需要导入模块: from werkzeug.wrappers import BaseResponse [as 别名]
# 或者: from werkzeug.wrappers.BaseResponse import headers['Access-Control-Allow-Origin'] [as 别名]
def __common_resp_handle(data, error, status):
"""
common response handling:
- add common response headers
- serialize response
@data must be json serializable
@error will be serialized with str()
"""
def __response_wrap(data=None, error=None):
"""
wrap response data/errors as dict - this should always be used when returning
data to allow easy return of list objects, assist in error case distinction, etc.
"""
return dict(data=data, error=error)
if not error:
error_str = None
else:
error_str = str(error) # convert any Exception objects to serializable form
ret_data = __response_wrap(data, error_str)
resp_payload = json.dumps(ret_data)
resp = Response(resp_payload, mimetype='application/json', status=status)
resp.headers['Access-Control-Allow-Origin'] = '*'
# more response processing
return resp