Skip to content

Instantly share code, notes, and snippets.

@vikas-git
Created February 28, 2019 06:37
Show Gist options
  • Save vikas-git/388f526e5a46c573d42734d8184eb9f3 to your computer and use it in GitHub Desktop.
Save vikas-git/388f526e5a46c573d42734d8184eb9f3 to your computer and use it in GitHub Desktop.
Django :: Create user define decorator
from django.http import HttpResponseRedirect
def authors_only(function):
def wrap(request, *args, **kwargs):
profile = request.user.get_profile()
if profile.usertype == 'Author':
return function(request, *args, **kwargs)
else:
return HttpResponseRedirect('/')
wrap.__doc__=function.__doc__
wrap.__name__=function.__name__
return wrap
and you can call it using @decoratorFunction name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment