Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,189 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