Skip to content
Myr

Mentioned View.decorators in the views docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent ef0f626 · Browse files · 1 file+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−0 removed

  • other:+21 added−0 removed

1 file+21 added−0 removed

modified:docs/views.rst+21 added
133 unmodified lines
134135That way you also don't have to provide the136:attr:`~flask.views.View.methods` attribute. It's automatically set based137on the methods defined in the class.138139Decorating Views140----------------141142Since the view class itself is not the view function that is added to the143routing system it does not make much sense to decorate the class itself.144Instead you either have to decorate the return value of145:meth:`~flask.views.View.as_view` by hand::146147 view = rate_limited(UserAPI.as_view('users'))148 app.add_url_rule('/users/', view_func=view)149150Starting with Flask 0.8 there is also an alternative way where you can151specify a list of decorators to apply in the class declaration::152153 class UserAPI(MethodView):154 decorators = [rate_limited]155156Due to the implicit self from the caller's perspective you cannot use157regular view decorators on the individual methods of the view however,158keep this in mind.