Html 是否可以使用 Flask 执行 Includes?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9679038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to perform Includes with flask?
提问by Michael
Say I have a template layout saved in template.html. This template includes a banner, side navigation, content container, and footer. Can I use flask to break up these page elements in such a way that I can have files such as banner.html, sidenavigation.html, etc. and render these different files within template.html?
假设我在 template.html 中保存了一个模板布局。此模板包括横幅、侧边导航、内容容器和页脚。我可以使用flask 以这样的方式分解这些页面元素,以便我可以拥有banner.html、sidenavigation.html 等文件并在template.html 中呈现这些不同的文件吗?
回答by Liyan Chang
From: http://jinja.pocoo.org/docs/templates/#include
来自:http: //jinja.pocoo.org/docs/templates/#include
template.html
模板.html
{% include 'banner.html' %}
{% include 'sidenavigation.html' %}
{% include 'content.html' %}
{% include 'footer.html' %}
回答by plaes
By default, Flask uses Jinja2 as its template engine. See Jinja's Template Designer Documentationhow it's done.
默认情况下,Flask 使用 Jinja2 作为其模板引擎。请参阅 Jinja 的模板设计器文档,了解它是如何完成的。