mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #25146 -- Allowed method_decorator() to decorate classes.
This commit is contained in:
committed by
Tim Graham
parent
1a76257b1b
commit
3bdaaf6777
@@ -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::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user