Hi Awesome Learners! welcome. In this part, we are going to explore the concept of template inheritance of Django.
Link: https://tutorialwithproject.com/templ...
Join :
/ jagwithyou
/ jagwithyou
https://github.com/jagwithyou
Think of a case from our page the navbar will be the same for all our pages. It's not good if we will write the same code again and again, are you thinking that we will take all the common codes to one HTML file and import them in others in this way we have to do less effort, Yes you are correct this is template inheriting and flask use jinja to perform this job.
so let's break our code. First, create a file navbar.html and paste all the common code there
navbar.html
django_basics/my_portfolio/templates/navbar.html
Now if you compare the code with the previous file we have just deleted the code of about section and given {% block content %} {% endblock%}. Any program extending this file and wants to write more all the codes are going to present over here, Don't be confused let's update the index.html you will understand better
about.html
django_basics/my_portfolio/templates/about.html
Now compare both the file you will get what block content is doing it is adding the file to the parent file.
Now save all and restart you will see your index page.
As always save all, restart the server and open the link you will see something awesome :)
Complete Playlist:
https://tutorialwithproject.com/what-...
https://tutorialwithproject.com/creat...
https://tutorialwithproject.com/hello...
https://tutorialwithproject.com/rende...
https://tutorialwithproject.com/stati...
https://tutorialwithproject.com/creat...
https://tutorialwithproject.com/add-a...
https://tutorialwithproject.com/templ...
https://tutorialwithproject.com/addin...
https://tutorialwithproject.com/link-...
Thank You
Keep Learning & Keep Growing
#TWP #DjangoTutorials #LearnOnLockdown