擅长:python、mysql、java
<p>您可以简单地修饰类本身,而不是重写分派方法或使用mixin。</p>
<p>例如</p>
<pre><code>from django.views.decorators.cache import cache_page
from django.utils.decorators import method_decorator
@method_decorator(cache_page(60 * 5), name='dispatch')
class ListView(ListView):
...
</code></pre>
<p>关于<a href="https://docs.djangoproject.com/en/2.0/topics/class-based-views/intro/#decorating-the-class" rel="noreferrer">decorating a method within a class based view.</a>的Django文档</p>