A node is created from each tag. You can understand how this works by reading how to write custom tags . Everything inside the tag will be its child. Here is an example comment tag from django docs:
def do_comment(parser, token): nodelist = parser.parse(('endcomment',)) parser.delete_first_token() return CommentNode()
as you can see the comment tag will analyze everything up to "endcomment" and will throw it away. Other tags will pass the nodelist to SometagNode() and will use it for rendering.
Rendering is done recursively. When render () is called in node, it renders on its children, etc.
The analysis is also performed recursively, so you can get nested tags, and parser.parse() can find a suitable matching closing tag, because when it parses and stumbles upon a tag, it calls the do_tag() thing, which in turn will call parser.parse() again parser.parse() to find the closest closing tag, and all of this will turn into node, return node, the higher parser.parse () will put it in the node list and continue searching for the closing tag.
The context object in the nodes is a kind of list of dicts structure. An additional context is pushed over the existing context and passed to the child nodes and issued after the node is displayed so that it does not affect the upper area.
For tags that do not have children, parser.parse() not used, so the node instance is returned without any children.
Ski
source share