diff options
| author | fabrizio ettore messina <fabrizio.messina@mistralpay.com> | 2015-08-11 13:35:50 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-09-18 19:04:29 -0400 |
| commit | 186eb21dc159807dba83148f7c9c50d470745708 (patch) | |
| tree | b906d98d94bde119bef7ee542cb842e91f1c51ab /docs/topics | |
| parent | d8d853378b3ff75c03d8bd91ea026d2b8c642b0f (diff) | |
Fixed #25269 -- Allowed method_decorator() to accept a list/tuple of decorators.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/class-based-views/intro.txt | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/docs/topics/class-based-views/intro.txt b/docs/topics/class-based-views/intro.txt index 0b4a02cfbb..5e3351e90c 100644 --- a/docs/topics/class-based-views/intro.txt +++ b/docs/topics/class-based-views/intro.txt @@ -286,9 +286,29 @@ of the method to be decorated as the keyword argument ``name``:: class ProtectedView(TemplateView): template_name = 'secret.html' +If you have a set of common decorators used in several places, you can define +a list or tuple of decorators and use this instead of invoking +``method_decorator()`` multiple times. These two classes are equivalent:: + + decorators = [never_cache, login_required] + + @method_decorator(decorators, name='dispatch') + class ProtectedView(TemplateView): + template_name = 'secret.html' + + @method_decorator(never_cache, name='dispatch') + @method_decorator(login_required, name='dispatch') + class ProtectedView(TemplateView): + template_name = 'secret.html' + +The decorators will process a request in the order they are passed to the +decorator. In the example, ``never_cache()`` will process the request before +``login_required()``. + .. versionchanged:: 1.9 - The ability to use ``method_decorator()`` on a class was added. + The ability to use ``method_decorator()`` on a class and the ability for + it to accept a list or tuple of decorators were added. In this example, every instance of ``ProtectedView`` will have login protection. |
