Fixed #25146 -- Allowed method_decorator() to decorate classes.

This commit is contained in:
Rigel Di Scala 2015-07-21 21:54:37 +01:00 committed by Tim Graham
parent 1a76257b1b
commit 3bdaaf6777
5 changed files with 102 additions and 9 deletions

View file

@ -279,8 +279,18 @@ that it can be used on an instance method. For example::
def dispatch(self, *args, **kwargs):
return super(ProtectedView, self).dispatch(*args, **kwargs)
In this example, every instance of ``ProtectedView`` will have
login protection.
Or, more succinctly, you can decorate the class instead and pass the name
of the method to be decorated as the keyword argument ``name``::
@method_decorator(login_required, name='dispatch')
class ProtectedView(TemplateView):
template_name = 'secret.html'
.. versionchanged:: 1.9
The ability to use ``method_decorator()`` on a class was added.
In this example, every instance of ``ProtectedView`` will have login protection.
.. note::