After receiving data from the user, we may either want to display it back to the user or store it in the database for later usage after processing it with our Python code. What we have at hand is python code data that the HTML has no business or no way coded to handle. These are two different worlds, the front end, and backend respectively. We need a way to call and interpolate these python objects into the Html template for the user to derive some business meaning out of it. We need a Jinja2 templating engine for that job. Yes, we could eliminate Jinja2 by turning our flask app to an API and having the front end handled by AJAX technologies or any front end frameworks like React, Vue, Angular, etc. In this post, we will be looking at how Jinja2 works and how best to use it in our flask applications.

In this tutorial we are going to look at how the jinja templating engine works. We will look at how it handles variable or python objects interpolation, conditional logic and finally template inheritance.

TABLE OF CONTENTS

  1. What is a template
  2. What is jinja and its features
  3. Jinja and its syntax
  4. Template inheritance
  5. Conclusion

Flask is a back end web development framework that depends on python. Technically we can’t have any backend code presented in the frontend html structures without the use of some interpolation techniques or technology. Jinja2 is that technique** or interpolation technology** developed in python.

#flask #web developemnt #flask #handling user requests #jinja2 templates #web development

How Jinja2 templates work: Python and flask web development part 5
1.60 GEEK