Understanding Django Template Tags




In django there are template tags that store python code so that we do not have to repeat code. For example if there is a nav bar than you can have a variable hold that code in base.html and extend it to other pages. After reading the documentation I learned about tag inheritance.

My question is this, do I have to place all of my django tags in base.html? I would think not but I am confused as to how django determines and defines what {block content is}. By that I mean If base.htmls code has the base format of the website and I want another template page to have the base.html code extended to it but I want a certain page to have its own block tags so that it can show its code on a third page, how would django know to look for and understand the block tags of the second template? Would I do an extends base.html extends template two, measure? Do I have to have unique names for the tags?

Put another way, if a block tag is not in base.html and is instead defined in another template, how can the third template know to look for the block tag in the second template?
Django docs link: The Django template language | Django documentation | Django

Gonna be a rubbernecker, here, since I don’t know Django; but, I do have past experience with PHP (the older stuff) and the mechanics of templating in that language.

When you speak of tags, I’m guessing that Django has those defined and itemized with usage examples and syntax? In PHP we would simply write a standard HTML page, then replace the dynamic elements of the page with the requisite <?php insertion. To avoid fatigue with multiple insertions we would use functions and insert their returns.

The focus is on the dynamic objects in play, and keeping in mind that we are building a document to respond to a request. The finished object will be a plain HTML document fired back at the client.

After all that gibberish, now I would ask you to post some demonstration code, enough to illustrate Django’s implementation of the above ideas. Perhaps in doing so, the muddle will unravel itself.