Is it possible to perform Includes with flask?

HtmlTemplatesFlaskJinja2Ssi

Html Problem Overview


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?

Html Solutions


Solution 1 - Html

From: <http://jinja.pocoo.org/docs/templates/#include>

template.html

{% include 'banner.html' %}
{% include 'sidenavigation.html' %}
{% include 'content.html' %}
{% include 'footer.html' %}

Solution 2 - Html

By default, Flask uses Jinja2 as its template engine. See Jinja's Template Designer Documentation how it's done.

Solution 3 - Html

Before you start, you need to write these components separately to other html files as pure html. For example, these files shouldn't contain any jinja syntax. After that, according to the documentation, you can easily import them into your template.html file by calling {% include 'filename.html' %} code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichaelView Question on Stackoverflow
Solution 1 - HtmlLiyan ChangView Answer on Stackoverflow
Solution 2 - HtmlplaesView Answer on Stackoverflow
Solution 3 - HtmlnedView Answer on Stackoverflow