Skip to main content

permission_required

Decorator for views that checks whether a user has a particular permission enabled, redirecting to the log-in page if necessary. If the raise_exception parameter is given the PermissionDenied exception is raised.

def permission_required(
perm: str | Iterable[str],
login_url: str | null = None,
raise_exception: bool = False
) - > function

Decorator for views that checks whether a user has a particular permission enabled, redirecting to the log-in page if necessary. If the raise_exception parameter is given the PermissionDenied exception is raised.

Parameters

NameTypeDescription
perm`strIterable[str]`
login_url`strnull` = None
raise_exceptionbool = FalseIf set to True, raises a PermissionDenied exception instead of redirecting to the login page when a user lacks permissions.

Returns

TypeDescription
functionA decorator function that wraps the view and enforces the specified permission checks.