Skip to content

Instantly share code, notes, and snippets.

@wunzeco
Created May 25, 2018 12:30
Show Gist options
  • Save wunzeco/342f7ce1e32fe54639217d5407d6c0ea to your computer and use it in GitHub Desktop.
Save wunzeco/342f7ce1e32fe54639217d5407d6c0ea to your computer and use it in GitHub Desktop.
jinja-example-iteritems
#!/usr/bin/env/python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from jinja2 import Environment
alphabets = {"a": "Apple", "b": "Butterfly", "c": "Car"}
title = "ABC tutorial"
templateString = """
Title: {{ title }}
{% for k,v in alphabets.iteritems() -%}
{{ k }} is for {{ v }}.
{% endfor -%}
...
"""
def print_html_doc():
print(Environment().from_string(templateString).render(title=title, alphabets=alphabets))
if __name__ == '__main__':
print_html_doc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment