Skip to content

Instantly share code, notes, and snippets.

@l2ol33rt
Created August 24, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l2ol33rt/1e6c58586d8eb0ae5c00182e2f70b935 to your computer and use it in GitHub Desktop.
Save l2ol33rt/1e6c58586d8eb0ae5c00182e2f70b935 to your computer and use it in GitHub Desktop.
Jinja DictLoader Example
from jinja2 import Environment, DictLoader
template = """{% for key, value in _dict.iteritems() %}
this is the {{ key }} whose value is {{ value }}
{% endfor -%}"""
j2_env = Environment(loader=DictLoader({'sample.txt': template}),
trim_blocks=True)
print j2_env.get_template('sample.txt').render(_dict={'linux': 4.4,
'bsd': 10.3})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment