Created
February 28, 2019 06:37
-
-
Save vikas-git/388f526e5a46c573d42734d8184eb9f3 to your computer and use it in GitHub Desktop.
Django :: Create user define decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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