Mentions
If session support is enabled, the view saves the language choice in the user’s session
Similarly, looking at the code:
def set_language(request):
"""
Redirect to a given URL while setting the chosen language in the session
(if enabled) and in a cookie. The URL and the language code need to be
specified in the request parameters.
Since this view changes how the user will see the rest of the site, it must
only be accessed as a POST request. If called as a GET request, it will
redirect to the page in the request (the 'next' parameter) without changing
any state.
"""
next_url = request.POST.get("next", request.GET.get("next"))
if (
next_url or request.accepts("text/html")
) and not url_has_allowed_host_and_scheme(
url=next_url,
allowed_hosts={request.get_host()},
require_https=request.is_secure(),
):
next_url = request.META.get("HTTP_REFERER")
This file has been truncated. show original
The docstring mentions setting value in session if enabled.
However, it looks like we removed this: Refs #15902 -- Stopped set_language() storing user's language in the … · django/django@d134b0b · GitHub
So is are the docs and docstring out of date, or is there another mechanism I’m missing? Happy to submit a PR to update the docs.
You are right, the docs need an update. I think that later in the page, we should also remove:
... It should come after SessionMiddleware, because LocaleMiddleware makes use of session data.
Please report the PR number, so that I can have a look.