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
| Name | Type | Description |
|---|---|---|
| perm | `str | Iterable[str]` |
| login_url | `str | null` = None |
| raise_exception | bool = False | If set to True, raises a PermissionDenied exception instead of redirecting to the login page when a user lacks permissions. |
Returns
| Type | Description |
|---|---|
function | A decorator function that wraps the view and enforces the specified permission checks. |