A lesson by lesson tutorial of the template engine Jinja2 in Python with Bootstrap and I18N.
This tutorial was written by Bruno Coudoin for a presentation made for the Toulibre's LUG in Toulouse France.
My first jinja2 template, all in Python.
Now the template is in a separate file. The python code is used to load it, execute it to create a text buffer out of it.
It is possible to create a base template with some parts maked as 'blocks'. Another template can extend it and fill the blocks.
Twitter's Bootstrap is an interesting technology to create a responsive Web site.
We can set variables in a template and access them in the base template.
Bootstrap uses a 12-column layout. It is possible to define how many columns should be used for a given content and for a given user screen size.
We can pass Python list to a Jinja2 template. In a template we can loop over them.
You can create macros in Jinja2 templates. These can be imported in other templates and be called anywhere and you can pass them parameters.
We will use pybabel to extract strings marked as {% trans %}Hello{% endtrans %}
in Jinja2 templates and strings marked as _('Hello')
in
the Python code.
We create a Makefile to make it easy to maintain our web site.