How do I include a HTML file in a Jinja2 template?

后端 未结 2 536
感动是毒
感动是毒 2020-12-12 20:10

I am using Flask micro-framework for my server which uses Jinja templates.

I have a parent template.html and some children templates called child1.

相关标签:
2条回答
  • 2020-12-12 20:43

    You can use the include statement.

    0 讨论(0)
  • 2020-12-12 20:56

    Use the jinja2 {% include %} directive.

    {% extends 'template.html' %}
    {% block content %}
        {% if task == 'content1' %}
            {% include 'content1.html' %}
        {% endif %}
        {% if task == 'content2' %}
            {% include 'content2.html' %}
        {% endif %}
    {% endblock %}
    

    This will include the content from the correct content-file.

    0 讨论(0)
提交回复
热议问题