class PermissionRequiredMixin
This mixin, just like the permission_required decorator, checks whether the user accessing a view has all given permissions. You should specify the permission (or an iterable of permissions) using the permission_required parameter:
from django.contrib.auth.mixins import PermissionRequiredMixin
class MyView(PermissionRequiredMixin, View):
permission_required = 'polls.can_vote'
# Or multiple of permissions:
permission_required = ('polls.can_open', 'polls.can_edit')
You can set any of the parameters of AccessMixin to customize the handling of unauthorized users.
You may also override these methods:
-
get_permission_required() -
Returns an iterable of permission names used by the mixin. Defaults to the
permission_requiredattribute, converted to a tuple if necessary.
-
has_permission() -
Returns a boolean denoting whether the current user has permission to execute the decorated view. By default, this returns the result of calling
has_perms()with the list of permissions returned byget_permission_required().
Please login to continue.