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