def cors(*args, **kwargs):
"""
A wrapper around flask-cors cross_origin, to also act on classes
**An extra note about cors, a response must be available before the
cors is applied. Dynamic return is applied after the fact, so use the
decorators, json, xml, or return self.render() for txt/html
ie:
@cors()
class Index(Mocha):
def index(self):
return self.render()
@json
def json(self):
return {}
class Index2(Mocha):
def index(self):
return self.render()
@cors()
@json
def json(self):
return {}
:return:
"""
def decorator(fn):
cors_fn = flask_cors.cross_origin(automatic_options=False, *args, **kwargs)
if inspect.isclass(fn):
apply_function_to_members(fn, cors_fn)
else:
return cors_fn(fn)
return fn
return decorator
评论列表
文章目录