Custom Python Decorator
Decorators allow developers to use aspect oriented approach. Here is an example of a custom python/django decorator that checks if the user is a super user and redirects it to login page if not
def super_user(func):Here is an example usage:
def call(request, *args, **kwds):
user = request.user
if user.is_authenticated() and user.is_superuser:
return func(request, *args, **kwds)
else:
return utils.redirect(settings.LOGIN_URL)
return call
@super_user
def my_view(request):
pass























Comments (0)