Skip to main content

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

NameTypeDescription
functioncallable = NoneThe view function to be decorated.
redirect_field_namestring = REDIRECT_FIELD_NAMEThe name of the query string parameter that will contain the URL the user should be redirected to after a successful login.
login_urlstring = NoneThe URL or named URL pattern where unauthenticated users will be redirected.

Returns

TypeDescription
functionA wrapped view function that enforces authentication or the decorator itself if no function was provided.