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

后端 未结 2 550
感动是毒
感动是毒 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: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.

提交回复
热议问题