Understanding Jinja
Jinja is a templating engine written in Python designed to help the rendering process of API responses. In every templating language, there are variables that get replaced with the actual values passed to them when the template is rendered, and there are tags that control the logic of the template.
The Jinja templating engine makes use of curly brackets { }
to distinguish its expressions and syntax from regular HTML, text and any other variable in the template file.
The {{ }}
syntax is called a variable block. The {% %}
syntax houses control structures such as if/else, loops, and macros.
The three common syntax blocks used in the Jinja templating language include the following:
{% … %}
– This syntax is used for statements such as control structures.{{ todo.item }}
– This syntax is used to print out the values of the expressions passed to it.{# This is a great API book! #}
– This syntax is used when writing comments...