title: How do I include a HTML file in a Jinja2 template?
body: <p>I am using Flask micro-framework for my server which uses Jinja templates.</p>
  <p>I have a parent <code>template.html</code> and some children templates called <code>child1.html</code> and <code>child2.html</code>, some of these children templates are pretty large HTML files and I would like to somehow split them for better lucidity over my work.</p>
  <p>Contents of my <code>main.py</code> script:</p>
  <pre><code>from flask import Flask, request, render_template
  
  app = Flask(__name__)
  
  @app.route('/')
  @app.route('/&lt;task&gt;')
  def home(task=''):
    return render_template('child1.html', task=task)
  
  app.run()
  </code></pre>
  <p>The simplified <code>template.html</code>:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;div class=&quot;container&quot;&gt;
        {% block content %}{% endblock %}
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>The magic is in <code>child1.html</code>:</p>
  <pre><code>{% extends 'template.html' %}
  {% block content %}
    {% if task == 'content1' %}
      &lt;!-- include content1.html --&gt;
    {% endif %}
    {% if task == 'content2' %}
      &lt;!-- include content2.html --&gt;
    {% endif %}
  {% endblock %}
  </code></pre>
  <p>Instead of the comments:</p>
  <pre><code>&lt;!-- include content1.html --&gt;
  </code></pre>
  <p>I have a lot of html text, and it is very hard to keep track of changes and not to make some mistakes, which are then pretty hard to find and correct.</p>
  <p>I'd like to just load the <code>content1.html</code> instead of writing it all in <code>child1.html</code>.</p>
  <p>I came across <a href="https://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file">this question</a>, but I had problems implementing it.</p>
  <p>I think Jinja2 might have a better tool for that.</p>
  <p><strong>NOTE:</strong> The code above might not be working properly, I just wrote it to illustrate the problem.</p>