Skip to content Skip to sidebar Skip to footer

How To Inherit A Flask Methodview Class Without Its Decorators?

For the reason of not rewriting the same API. I want to inherit a get method from an already created MethodView and ignore the login_required decorator. class DoStuffA(MethodView):

Solution 1:

The View.decorators list is applied only when the View.as_view() method is called. If you don't want any decorators to be applied in your subclass, just override the attribute with an empty sequence:

classDoStuffB(DoStuffA):
    decorators = ()  # empty tuple

Now DoStuffB.as_view() will find the empty tuple rather than the inherited DoStuffA.decorators list, and no decorators are applied.

Post a Comment for "How To Inherit A Flask Methodview Class Without Its Decorators?"