How Does The 'with' Statement Work In Flask (jinja2)?
In Python you can use the with statement like this (source): class controlled_execution: def __enter__(self): # set things up return thing def __exit__(self
Solution 1:
{% with %}
statement in Jinja lets you define variable, but limits the scope of a variable with the {% endwith %}
statement. For example :
{% with myvar=1 %}
...
{% endwith %}
Any elements declared in the body will have access to the myvar variable.
Please, refer - https://www.webforefront.com/django/usebuiltinjinjastatements.html
Solution 2:
The with
statement in Flask is not the same as the with
statement in Python.
Within python the equivalent would be this:
messages = get_flashed_messages()
Post a Comment for "How Does The 'with' Statement Work In Flask (jinja2)?"