Created
May 25, 2018 12:30
-
-
Save wunzeco/342f7ce1e32fe54639217d5407d6c0ea to your computer and use it in GitHub Desktop.
jinja-example-iteritems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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