Skip to main content

PermissionRequiredMixin

Verify that the current user has all specified permissions.

Attributes

AttributeTypeDescription
permission_requiredstring or iterable = nullThe permission or iterable of permissions that the user must possess to access the view.

Methods


get_permission_required()

@classmethod
def get_permission_required() - > iterable

Override this method to override the permission_required attribute. Must return an iterable.

Returns

TypeDescription
iterableA collection of permission strings required to access the view.

has_permission()

@classmethod
def has_permission() - > boolean

Override this method to customize the way permissions are checked.

Returns

TypeDescription
booleanTrue if the current user has all required permissions, False otherwise.

dispatch()

@classmethod
def dispatch(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
*args: any,
**kwargs: any
) - > [HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)

Intercepts the request to verify user permissions before proceeding with standard request handling.

Parameters

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The incoming HTTP request object to be validated.
*argsanyPositional arguments passed to the view.
**kwargsanyKeyword arguments passed to the view.

Returns

TypeDescription
[HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)The standard HTTP response if authorized, or the result of handle_no_permission() if unauthorized.