Created
October 21, 2012 19:48
-
-
Save johnschimmel/3928235 to your computer and use it in GitHub Desktop.
Dictionary in dictionary to Jinja2 example
This file contains hidden or 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
# 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) | |
This file contains hidden or 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
{# 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