How to apply a decorator to all views (of a module) in django -
it happens lot, when views in specific module supposed available when user authorized, or should same checks.
how avoid repeating annotations on file?
when using class-based views can create base class/mixin these views implements desired functionality (also using decorators) , have views inherit base view.
from django.views.generic import templateview class baseview(templateview): def get(self, request, *args, **kwargs): # checking here if not request.user.is_authenticated(): # if anonymous user return super(baseview, self).get(request, *args, **kwargs) class myview(baseview): pass
Comments
Post a Comment