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

Python Flask Basics Character Builder Loop Nested Items

Loop through each of the teachers in teachers and create an <li> for them in the provided <ul>. Inside the <li>, create

Loop through each of the teachers in teachers and create an <li> for them in the provided <ul>. Inside the <li>, create an <h2> that holds the teacher's 'name' key.

code not returning names, please help =)

flask_app.py
from flask import Flask, render_template

from teachers import TEACHERS

app = Flask(__name__)


@app.route('/')
def index(name):
  string_dict = {}
  for word in teachers():
    if word in teachers:
        name[word] += 1
    else:
        name[word] = 1
  return render_template("teachers.html", teachers=TEACHERS)
templates/teachers.html
<ul class="teachers">

<ul>
{% for item in options %}
  <li>{{ TEACHERS  }} </li> 
{% endfor %}
</ul>


</ul>

5 Answers

Dan Johnson
Dan Johnson
40,532 Points

The variable you're working with in the template file is teachers, TEACHERS is what it was set to.

Now when you're iterating through the teachers you'll be using item to access the current teacher. Then from item you'll want to get the name value:

{% for item in teachers %}
  <li><h2>{{ item["name"] }}</h2></li>
{% endfor %}
abdulkadir yıldız
abdulkadir yıldız
2,711 Points

try this

from flask import Flask, render_template

from teachers import TEACHERS

app = Flask(__name__)


@app.route('/')
def index():
    return render_template("teachers.html", teachers=TEACHERS)
<ul class="teachers">
  {% for item in teachers %}
  <li><h2>{{ item["name"] }}</h2></li>
  {% endfor %}
</ul>
Mariana Hoffmann
PLUS
Mariana Hoffmann
Courses Plus Student 11,046 Points

hello... i'm stuck here can't get it right... i'm getting a 'syntax error' on line 1 column 54 but i couldn't find it

please help!!

from flask import Flask, render_template

from teachers import TEACHERS

app = Flask(__name__)


@app.route('/')
def index(name):
    string_dict = {}
    for word in teachers():
        if word in teachers:
            name[word] += 1
        else:
            name[word] = 1
            return render_template("teachers.html", teachers=TEACHERS)
<ul class="teachers">
<ul>

{% for item in teachers %}
  <li><h2>{{ item["name"] }}</h2></li>
{% endfor %}
</ul>
</ul>

thanks =) I understand this much better

This is so stupid. why couldn't they just say it's a dict from the beginning.