Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer is yes, all nodes are created when you create a Template object. But the magic happens when you call the render method of this object. This Template object has a NodeList with it that is rendered within a context. This rendering is done as you said before, depth first, and it just gets the inners child strings (html) appended to the father Node. <a href="https://github.com/django/django/blob/master/django/template/base.py" rel="nofollow">Here is the NodeList class</a> where the node rendering is done. So, the root node is the one to get all the nodes appended to it to finally generate the file. And if you remember, the extends template tag must be first in the template so it becomes the root node who get all the already rendered nodes in it.</p> <p>Now, what about inheritance? How is the exteds root node rendered? Well, I haven't figured out all about the context role here, but there is a <a href="https://github.com/django/django/blob/master/django/template/loader_tags.py" rel="nofollow">ExtendsNode</a> that is created by the extends template tag. This type of node recieves the parent template name (your base template) and a context with all the variables, blocks and nodes of the child template (the one you actually call to render). So when this node is rendered, it does the same thing that every node does, append his child nodes. The main difference in this class is that it gets the nodes marked with the block template tag from the child's template context, and appends it everywhere you defined a block template tag with that name in the parent template.</p> <p>So the nodes are created first, and the extends template tag manage to get them when you render the template.</p> <p>If you want to know how nodes a created, you can look for <a href="https://github.com/django/django/blob/master/django/template/base.py" rel="nofollow">the Token and Parser class</a> at the Django code.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload