Jinja Template

A template contains variables and/or statements, which get replaced with values when a template is rendered.

  • Variables
<h1></h1>
  • Statements
{% if detail: %}
<table>
  {% for key, value in detail.items(): %}
  <tr>
     <th>{{ key }}</th>
     <td>{{ value }}</td>
  </tr>
  {% endfor %}
</table>
{% endif %}
  • Inheritance

Define a Base Template: index.html

<!DOCTYPE html>
<html lang="en">
<head>
    {% block head %}
    <title>{% block title %}{% endblock %}</title>
    {% endblock %}
</head>
<body>
    <div id="content">{% block content %}{% endblock %}</div>
    <div id="footer">{% block footer %}{% endblock %}</div>
</body>
</html>

A Child Template:weather.html that inherits the Base Template: index.html

{% extends "index.html" %}
{% block content %}
<div>
    <form>
    ...
    </form>
</div>
{% endblock %}

results matching ""

    No results matching ""