How to apply a decorator to all views (of a module) in django
In your urls
url(r'someregexp/$', mydecorator(view.myview.dude), 'name_of_view'),
When using class-based views you can create a base class/mixin for all these views which implements the desired functionality (also using decorators) and then have all the views inherit from this base view.
from django.views.generic import TemplateView
class BaseView(TemplateView):
def get(self, request, *args, **kwargs):
# do some checking here
if not request.user.is_authenticated():
# do something if anonymous user
return super(BaseView, self).get(request, *args, **kwargs)
class MyView(BaseView):
pass