Skip to content

Instantly share code, notes, and snippets.

@canit00
Forked from wunzeco/jinja-example-iteritems.py
Created September 22, 2018 18:15
Show Gist options
  • Save canit00/f0bfb7ea55b1d98924c4f57f0866b27a to your computer and use it in GitHub Desktop.
Save canit00/f0bfb7ea55b1d98924c4f57f0866b27a 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