当前位置: 动力学知识库 > 问答 > 编程问答 >

Breaking up large django templates: when {% include %} and {% ssi %} don't have enough context

问题描述:

Django's {% include %} and {% ssi %} can render or incorporate a template. But they are designed to process the template and return the HTML. As the docs say "This means that there is no shared state between included templates – each include is a completely independent rendering process."

But what if I want shared context? What if I {% include 'extra/map.html' %} and need to add a block to the <head> section? How can I best break up a large template into parts, and keep the context? The {% include %} mechanism seems potentially much clearer than extending the base, but the context issue gets in the way.

See also Including django templates in other templates so they are actually parsed

分享给朋友:
您可能感兴趣的文章:
随机阅读: