Using Jina Templating

I have used Jinja in all of my projects that use Flask. It’s a simple way to get Python syntax into a HTML page.
Details about the project and full documentation can be found here.

I will show how I have used Jinja in my Multicast Daskboard, part of my Scrapli and Flask Project.

I have passed into the HTML page two variables. One is a list of dictionaries (parsed_output) and the second a dictionary (show_output_dict).

List of Dictionaries (parsed_output) Tab1

The list of dictionaries contains all of the data parsed from my TextFSM template for each Nexus switch.

In the HTML file I am using Jinja to;

  • Pull out the hostname values mcast_Nexus1,2,3,4
  • Pull out the multicast_group_ip for each hostname

List of Dictionaries (parsed_output) Tab 2

For the next tab I have used a similar method as in the first tab, oulling out the hostname and thenthe details for that hostname.
An addition here is that not all dictionary keys are populated so there are if statements in here that can display differen text in the HTML page based off what is in the dictionary or not.

Dictionary (show_output_dict) Tab 3

This tab I am showing the output from the Cisco switch with a heading of the hostname above. The output is displayed inside code tags and the heading is a paragraph, but in bold.
Again this is using a nested for loop similar to tab1 to get the hostname out.

Leave a Comment

Your email address will not be published. Required fields are marked *