Skip to main content

Use multiple permission classes in django class based views.

Project description

Django multiple permissions

Python License


  • Install the package.
$ pip install multiple-permissions
  • Add multiple_permissions to installed apps.
  • Add PermissionMiddleware to MIDDLEWARE list.
  • Set permission_classes attribute to view classes.
  • Set exception_class attribute to view classes.
from django.views.generic import ListView, CreateView

from multiple_permissions.permissions import IsAuthenticated, IsSuperuser, IsManager

class PollsListView(ListView):
    multiple_permissions = (IsAuthenticated,)
    # if exception_class is missing will raise django.core.exceptions.PermissionDenied

class PollsCreateView(CreateView):
    multiple_permissions = (IsSuperuser, IsManager)
    exception_class = PermissionError

Creating new permissions

  • create new file in your apps named and write the followng code

  • note that your user should have is_manager attribute or model field otherwise you'll catch AttributeError

from multiple_permissions.permissions import BasePermission

class IsManager(BasePermission):
    def has_permission(self, request, view=None):
        if request.user.is_authenticated and request.user.is_active and request.user.is_manager:
            return True
        return False

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multiple_permissions-0.2.2.tar.gz (3.0 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page