About Decorators for Class-based Views
To apply view decorators (like @never_cache or @login_required) to a django class-based view, you need to wrap them with @method_decorator:
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
@method_decorator(login_required, name="dispatch")
class DashboardView(TemplateView):
template_name = "accounts/dashboard.html"
Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2
Also by me
Django Messaging 🎅🏼
For Django-based social platforms.
Django Paddle Subscriptions 🎅🏼
For Django-based SaaS projects.
Django GDPR Cookie Consent 🎅🏼
For Django websites that use cookies.