django-planet
Sept. 7, 2024

Django: hoist repeated decorator definitions

published by Adam Johnson
in blog Adam Johnson
original entry Django: hoist repeated decorator definitions

Django provides us with a rich set of view decorators. In this post, we’ll look at a technique for hoisting repeated use of these decorators to reduce repetition.

Repeated @cache_control calls

Here are two public views with the same @cache_control decorator:

from django.views.decorators.cache import cache_control


@cache_control …