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

Now add a new <ul> inside of the <li> with a class of "courses". Inside this <ul> loop through the teacher's 'courses' k

Just can't seem to get this challenge answered correctly. I feel like I'm right on the edge of it.

Please!

flask_app.py
from flask import Flask, render_template

from teachers import TEACHERS

app = Flask(__name__)


@app.route('/')
def index():
    return render_template("teachers.html", teachers=TEACHERS)
templates/teachers.html
<ul class="teachers">
  {% for teacher in teachers %}
    <li>
      <h2> {{ teacher['name'] }} </h2>
      <ul class="courses">
        {% for course in teachers['courses'] %}
          <li>{{ course['courses'] }}</li>
        {% endfor %}
      </ul>
    </li>
  {% endfor %}

</ul>
Antonio Falcetta
Antonio Falcetta
14,192 Points

Try it this way

<ul class="teachers">
  {% for teacher in teachers %}
    <li>
      <h2> {{ teacher.name }} </h2>

      <ul class="courses">
        {% for course in teacher['courses'] %}
          <li>{{ course }}</li>
        {% endfor %}
      </ul>

    </li>
  {% endfor %}
</ul>

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Wes;

Yes, you are very close indeed.

Take a look at your second for loop, we just want to print out the course inside the loop, correct? Not an attribute ['courses'] of course. That one small change in your code will make it work.

Post back if you are still stuck and happy coding,
Ken

Thanks Ken.

I managed to figure it out from another students question on the topic. I also , in the process, learned to browse the forum for answers more effectively. Can't believe it took me so long to figure out where other questions on the same topic were.

Win win