Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Created October 21, 2012 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnschimmel/3928235 to your computer and use it in GitHub Desktop.
Save johnschimmel/3928235 to your computer and use it in GitHub Desktop.
Dictionary in dictionary to Jinja2 example
# put this in your app.py
@app.route("/nuts")
def nutbutter():
# nuts and review
nuttbutterReviews = {
'almond' : 'great',
'peanut' : 'okay',
'walnut' : 'what is this stuff?'
}
templateData = {
'nutbutters' : nuttbutterReviews
}
return render_template('nut.html', **templateData)
{# NOTE - put this file in your template directory #}
{% extends "layout/main.html" %}
{% block body %}
{# NOTE - loop through a dictionary's key and values with .iteritems #}
{% for nut,taste in nutbutters.iteritems() %}
{# NOTE - display the nut's name and the taste #}
{{ nut }} = {{ taste }}<br>
{% endfor %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment