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

You can use the include statement.


I'd like to add the proper syntax for using include, one given above works fine, but when it comes to the path, it took some time to find this, it is not even mentioned in the official document.

Syntax for include is:

{% include 'path_to_template_file' %}

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.