Art Art - 1 year ago 76
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
Answer Source

"... 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download