Templates

Jinja is a fast, expressive, extensible templating engine!
Installation
Jinja is already installed if you are installed flask 😀
Flask uses the Jinja template engine for rendering HTML files. By defining your Flask application, it sets the default path of templates dir ( it is templates/` ).
- Import
render_templatefunction fromflaskon your code. - Create
templates/directory and any*.htmlfile.
Rendering Templates
Give your template's name as an argument to the render_template function.
1 2 3 4 5 6 7 8 9 10 11 | |
| It works 👀 |
We can also pass variables from our python code to our templates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
You should write(use) passed variable in your template between curly braces:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Variables
directory- the name of our variable that we want to pass.app.template_folder- flask app's default template dir.