Template (Flask)
A Flask template is an HTML file (stored in the templates/ folder) containing Jinja2 placeholders. Flask renders it into final HTML by combining the file with data passed from a view function.
Flask
Templates keep your HTML out of your Python code. Instead of building markup with string concatenation, you write a normal .html file with {{ }} and {% %} tags and let Jinja2 fill in the dynamic parts.
Flask discovers templates in a folder named templates/ next to your application package by default. You render one by calling render_template('name.html', **context), where the keyword arguments become variables available inside the file.
Template inheritance is the key organizing tool: a base.html defines the page skeleton with {% block content %}, and child templates {% extends 'base.html' %} and override only the blocks they need.
Syntax
render_template("page.html", title="Home")Examples
Python
<!-- templates/base.html -->
<html><body>{% block content %}{% endblock %}</body></html>
<!-- templates/home.html -->
{% extends 'base.html' %}
{% block content %}<h1>{{ title }}</h1>{% endblock %}