Passing variables from Python to a template
So far, we have only seen a static template and we have not passed any information from our Python script back into the template.
The power of this concept, however, is that we can pass information that we have obtained in our Python script, for example, by querying an API or by parsing the output of an SSH command we issued on a device, and use that information in our template.
Luckily, Jinja2 supports an easy mechanism for passing variables from our script into our template, so in this recipe, we will see how we can do this.
Getting ready
Open your code editor and start by creating a file called vars.py
. Next, navigate your terminal to the same directory that you just created the vars.py
file in.
In the same directory as your Python file, create a directory called templates
if you have not already done so in a previous recipe. Inside of this directory, create a file called vars.conf.tpl
.
How to do it...
Let&apos...