Skip to content

Instantly share code, notes, and snippets.

@Alir3z4
Created June 1, 2013 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alir3z4/5690971 to your computer and use it in GitHub Desktop.
Save Alir3z4/5690971 to your computer and use it in GitHub Desktop.
Decorator to check whether user is super user or not If user is not a super-user, it will raise PermissionDenied or 403 Forbidden.
from functools import wraps
from django.core.exceptions import PermissionDenied
def superuser_required(method):
"""
Decorator to check whether user is super user or not
If user is not a super-user, it will raise PermissionDenied or
403 Forbidden.
"""
@wraps(method)
def _wrapped_view(request, *args, **kwargs):
if request.user.is_superuser is False:
raise PermissionDenied
return method(request, *args, **kwargs)
return _wrapped_view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment