Skip to content
Advertisement

How can Jinja2 read a function without passing it explicitly?

In the flask:flashing documentation, I encounter the following situation.

JavaScript

And here is the Jinja2 used HTML file.

JavaScript

So I wonder that even if there is no function passed in to the HTML file by using return statement in Python file, Jinja2 can read get_flashed_messages() function, which is a function under the flask module. How is this possible?

Advertisement

Answer

Messages to be flashed get appended to session, a global object that has access to along with what you return in your route functions.

From the github repo flask/src/flask/helpers.py:

JavaScript

‘s source code is available on github and it is well worth the exploration.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement