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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -