Art Art - 5 months ago 29
Python Question

On render(), how does Django know which language to pick?

I am just very curious. Django runs the following line:

email_body = get_template("applicant/email_with_token.txt").render(Context())

it runs it from
of a class-based view. New context is created based on a regular python dictionary. No parameters are passed, that come from a view, user, session, etc... Inside of the template there is
{% load i18n %}
and a bunch of context/variables.

Still, Django recognizes the language of the current session and applies appropriate translations.

So, where from does it know the session language?

Art Art

"... decides what translation object to install in the current thread context" (source)

Simple as it is, the language is thread-wide, since one thread serves one request, and request knows about the language.