Skip to main content

LogoutView

Log out the user and display the 'You are logged out' message.

Attributes

AttributeTypeDescription
http_method_nameslist = ["post", "options"]List of allowed HTTP methods for the view, restricted to POST and OPTIONS to ensure logout actions are not triggered by GET requests.
template_namestring = "registration/logged_out.html"The path to the template used to render the 'logged out' confirmation page.
extra_contextdict = nullA dictionary of additional context variables to be passed to the template engine during rendering.

Methods


post()

@classmethod
def post(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
args: list,
kwargs: dict
) - > [HttpResponseRedirect](../../../http/response/httpresponseredirect.md?sid=django_http_response_httpresponseredirect)

Logout may be done via POST.

Parameters

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The current HTTP request object containing the user session to be terminated.
argslistPositional arguments passed to the view handler.
kwargsdictKeyword arguments passed to the view handler.

Returns

TypeDescription
[HttpResponseRedirect](../../../http/response/httpresponseredirect.md?sid=django_http_response_httpresponseredirect)A redirect response to the success URL after the session is cleared, or the rendered template if the redirect target is the current path.

get_default_redirect_url()

@classmethod
def get_default_redirect_url() - > str

Return the default redirect URL.

Returns

TypeDescription
strThe resolved URL path where the user should be sent after logging out, prioritized by the next_page attribute, settings, or the current request path.

get_context_data()

@classmethod
def get_context_data(
kwargs: dict
) - > dict

Constructs the template context dictionary, including site information and localized titles for the logout page.

Parameters

NameTypeDescription
kwargsdictAdditional keyword arguments to be merged into the template context.

Returns

TypeDescription
dictA dictionary containing site, site_name, title, and any additional extra_context provided to the view.