mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #25146 -- Allowed method_decorator() to decorate classes.
This commit is contained in:
parent
1a76257b1b
commit
3bdaaf6777
5 changed files with 102 additions and 9 deletions
|
@ -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::
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue