Calling block inside an if condition: django template

杀马特。学长 韩版系。学妹 提交于 2019-12-03 01:09:36

You haven't made a mistake - template blocks are included regardless of any conditionals around them. You can see this from this line of the ExtendsNode class of django/template/loader_tags.py in the Django source code:

self.blocks = {n.name: n for n in nodelist.get_nodes_by_type(BlockNode)]}

When the {% extends %} is being rendered, it fetches all block nodes from the template directly and stores them for rendering when the parent comes across those blocks. Whether those blocks in the child were inside conditionals or not isn't considered.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!