Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What to expect in part 2 of jinja2?


Asked by Diego Gould on Dec 06, 2021 FAQ



Welcome to part 2 of my Jinja2 Tutorial. In part 1 we learned what Jinja2 is, what are its uses, and we started looking at templating basics. Coming up next are loops and conditionals, sprinkled with tests and a healthy dose of examples! In Jinja2 loops and conditionals come under name of control structures, since they affect flow of a program.
Thereof,
Jinja2 comes with a lot of great features: 1 Control structures (loops and conditional statements) 2 Rich set of built-in filters and tests 3 Template inheritance 4 Macros 5 Support for custom filters 6 HTML escaping 7 Sandbox environment for safely rendering untrusted templates 8 Easy to debug 9 Configurable syntax
Likewise, If you are using Python 3.2 you can use an older release of Jinja2 (2.6) as support for Python 3.2 was dropped in Jinja2 version 2.7. If you wish to use the PackageLoader class, you will also need setuptools or distribute installed at runtime. You have multiple ways to install Jinja2.
Consequently,
So, Jinja2 templating is being used. A template contains variables which are replaced by the values which are passed in when the template is rendered. Variables are helpful with the dynamic data. The structure of your application helps to keep your code organised and accessible.
And,
Jinja2 supports extensions that can add extra filters, tests, globals or even extend the parser. The main motivation of extensions is it to move often used code into a reusable class like adding support for internationalization. Extensions are added to the Jinja2 environment at creation time.