login_required
Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary.
def login_required(
function: callable = None,
redirect_field_name: string = REDIRECT_FIELD_NAME,
login_url: string = None
) - > function
Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary.
Parameters
| Name | Type | Description |
|---|---|---|
| function | callable = None | The view function to be decorated. |
| redirect_field_name | string = REDIRECT_FIELD_NAME | The name of the query string parameter that will contain the URL the user should be redirected to after a successful login. |
| login_url | string = None | The URL or named URL pattern where unauthenticated users will be redirected. |
Returns
| Type | Description |
|---|---|
function | A wrapped view function that enforces authentication or the decorator itself if no function was provided. |