The return value of the wrapped function is passed (as a single argument) to flask.make_response() ; anything that can return the flask to its normal form is acceptable. The decorator is essentially the same as this flash fragment .
Since Flask-restful Resource is a subclass of flask.views.MethodView , you really shouldn't put decorators directly on methods here. As described in Finishing Views , you must specify view decorators in a special attribute of the decorators class, which is a list:
class HelloWorld(restful.Resource): decorators = [cors.crossdomain(origin='*')] def get(self): return {'hello': 'world'}
and the flag will apply the view to the real view method returned by HelloWorld.as_view() , which actually calls Flask when sending the route to the view.
Only the server will apply them directly to the methods to confuse the restful.Resource dispatcher, since it expects the methods to return python data directories suitable for encoding in JSON, which is not what cors.crossdomain() returns anyway.
source share