Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Error when looping through dictionaries

Whenever I am trying to loop through dictionaries in my html document, I am getting an error:

jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'

with a code like this:

{% for i in {{Database.items()}} %}
<p>ID  {{i[0]}}</p>
{% for j in i[1] %}
<p>{{j}}</p>
{% endfor %}
{% endfor %}

In this this case, the keys of the dictionary are strings and the values are lists. What daoes this error mean and how do i fix it?

1 Answer

Between {% and %}, you can use variables without surrounding them with {{ and }}. Try changing {% for i in {{Database.items()}} %} to {% for i in Database.items() %}