Jinja

Jinja is a powerful and widely used templating engine for Python. It allows you to separate the presentation layer from the business logic in your Python web applications.

Install Jinja with pip install jinja2

Import the Jinja2 module in your Python code with from jinja2 import Environment, FileSystemLoader.

To use Jinja2, you need to define an environment and a template loader. The environment is responsible for managing the templates, while the template loader finds the template files on the filesystem.

Create the Jinja2 environment with env = Environment(loader=FileSystemLoader('/path/to/templates')).

Load a specific template with template = env.get_template('template_name.html').

Once you have a template loaded, you can render it by passing variables to it output = template.render(variable1=value1, variable2=value2).

The variable1, variable2, etc., are the placeholders defined in the template, which will be replaced with the corresponding values.

from jinja2 import Environment

template = Environment().from_string("Hello, {{ name }}!")
output = template.render(name="World")
print(output)

Hello, World!