jinja import code example

Example 1: jinja inheritance

<!DOCTYPE html>
<html lang="en">
<head>
    {% block head %}
    <link rel="stylesheet" href="style.css" />
    <title>{% block title %}{% endblock %} - My Webpage</title>
    {% endblock %}
</head>
<body>
    <div id="content">{% block content %}{% endblock %}</div>
    <div id="footer">
        {% block footer %}
        © Copyright 2008 by <a href="http://domain.invalid/">you</a>.
        {% endblock %}
    </div>
</body>
</html>

Example 2: jinja inheritance

{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
    {{ super() }}
    <style type="text/css">
        .important { color: #336699; }
    </style>
{% endblock %}
{% block content %}
    <h1>Index</h1>
    <p class="important">
      Welcome to my awesome homepage.
    </p>
{% endblock %}

Example 3: python jinja2 from string

from jinja2 import Environment, BaseLoader

rtemplate = Environment(loader=BaseLoader()).from_string(myString)
data = rtemplate.render(**data)

Example 4: jinja2 template import html with as

{% from 'forms.html' import input with context %}
{% include 'header.html' without context %}