python - Decorate methods in derived classes of Flask MethodView -
i thought able require login derived views decorating __enter__
follows:
from flask.views import methodview flask.ext.login import login_required class loggedinview(methodview): @login_required def __enter__(self): pass
if add logging, turns out __enter__
not entered. similarly, __exit__
doesn't happen.
what's going on here?
i can modify style decorate other function, it's necessary call super()
in derived views defeats point of doing begin with.
how can enforce decoration without work in views beyond inheriting loggedinview
?
to decorate methods of methodview
instance have add decorators
class variable list of decorators call. see documentation.
for example, be:
from flask.views import methodview flask.ext.login import login_required class loggedinview(methodview): decorators = [login_required] def get(self): pass def post(self): pass # ...
note decorators applied methods defined.
Comments
Post a Comment