1from jinja2 import Environment 2from jinja2.loaders import DictLoader 3 4env = Environment( 5 loader=DictLoader( 6 { 7 "child.html": """\ 8{% extends master_layout or 'master.html' %} 9{% include helpers = 'helpers.html' %} 10{% macro get_the_answer() %}42{% endmacro %} 11{% title = 'Hello World' %} 12{% block body %} 13 {{ get_the_answer() }} 14 {{ helpers.conspirate() }} 15{% endblock %} 16""", 17 "master.html": """\ 18<!doctype html> 19<title>{{ title }}</title> 20{% block body %}{% endblock %} 21""", 22 "helpers.html": """\ 23{% macro conspirate() %}23{% endmacro %} 24""", 25 } 26 ) 27) 28tmpl = env.get_template("child.html") 29print(tmpl.render()) 30