from jinja2 import Template # render template # http://jinja.pocoo.org/docs/2.10/intro/#basic-api-usage # htmlfragment = """ # {{ content }} # """ # template = Template(htmlfragment) # htmlrendered = template.render(content="Jinja What??", # id="iamid") # print(htmlrendered) xpub1 = ["Pedro","Rita","Simon","Artemis","Bo","Biyi"] xpub2 = ["Tash", "Angeliki","Alice","Alex", "Joca", "Zalan"] users_html = Template(''' ''') users_1 = users_html.render(users=xpub1) users_2 = users_html.render(users=xpub2) print(users_1, users_2) # template-inheritance # http://jinja.pocoo.org/docs/2.10/templates/#template-inheritance from jinja2 import FileSystemLoader from jinja2.environment import Environment env = Environment() env.loader = FileSystemLoader('.') tmpl = env.get_template('child.html') tmpl_render= tmpl.render(mytitle="xpUB", content=users_1 + users_2) print(tmpl_render) # save with open("index.html","w") as index: index.write(tmpl_render) # contro structures # http://jinja.pocoo.org/docs/2.10/templates/#list-of-control-structures # print(users_html.render(users=xpub))