from flask_login import login_required
from flask_restful import Resource
@login required
class MyClass(Resource):
#...
In the main file I call the class's methods like:
api.add_resource(MyClass, '/some_url', methods=['GET', 'PUT', 'POST', 'DELETE'])
I think I am using @login_required the wrong way here, since I get the error
AttributeError: 'function' object has no attribute 'as_view'
So I am assuiming that @login_required can only be used with functions. Is there a way to incorporate it with a class?
you could give the class the decorators it should run :
class MyClass(Resource):
decorators = [login_required]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With