Inheriting templates
What is template inheritance?
Template inheritance in simple words means using one main template structure in all the files.
For example : If we have a static part of the website which is the same in all the pages like navbar, footer,etc, Nobody would like to repeat the code in all the pages. Major problem is when you got a small change in the navbar you have to go to each page and change it. So Using templates we can write the navbar code in the main template and just extend that in all other files we want to use it.
How to inherit a main Template?
To inherit a template, we have to first create a file and let's name it maintemp.html. Write a basic html structure in the maintemp.html as shown below and add the block with the blockname in a tag "{% %}".
You can also use the url in the tag as shown in the above example.
Now when you create a new file, you don't have to repeat the html structure or the navbar, and other static codes. You can directly extend this template in the new pages you create as shown below.