Having to override
dispatch() in each and every one of our views is an unacceptable method for adding permissions. We should be able to use decorators on our class-based views directly. Even though Django doesn’t supply this behavior, because this is all Python, we can create our own decorators.
Decorators are one of Python’s trickier techniques, and even though Appendix B provides a primer on the material, we will take this slowly. To begin, we recreate the
@login_required decorator a new file called
user/decorators.py, as shown in Example 20.39.
1 from django.conf import settings 2 from django.contrib.auth import get_user ...