Block composition and layout inheritance
Usually, any web application will have a number of web pages that will be different from each other. Code blocks such as headers and footers will be the same in almost all the pages throughout the site. Likewise, the menu also remains the same. In fact, usually, just the center container block changes, and the rest usually remains the same. For this, Jinja2 provides a great way of inheritance among templates.
It's a good practice to have a base template where we can structure the basic layout of the site along with the header and footer.
Getting ready
In this recipe, we will try to create a small application where we will have a home page and a product page (such as the ones we see on e-commerce stores). We will use the Bootstrap framework to give a minimalistic design to our templates. Bootstrap can be downloaded from http://getbootstrap.com/.
Here, we have a hardcoded data store for a few products placed in the models.py
file. These are read in...