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

toirleachomalley
toirleachomalley
11,971 Points

Problems with Task 2 in this quiz. It is the only outstanding item I have from finishing the Flask basics.

I've tried several attempts at this but without any debugging or being able to see the relevant objects, I cannot complete this. This means I do not complete the course...mega frustrated and sad face!!

my final attempt. I know it is something simple but I'm just very frustrated at this point. Perhaps being able to do a bit of debugging in more challenging quizzes would be an idea??

<ul class="teachers">
{% for teacher in teachers %} <li><h2>{{ teacher.get('name') }}</h2> <ul class="courses"> {% for course in teacher.courses() %} <li>{{ course }}</li> {% endfor %} </ul> </li> {% endfor %} </ul>

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.get('name') }}</h2> 
    <ul class="courses">
    {% for course in teacher.courses() %}
        <li>{{ course }}</li>
    {% endfor %}
    </ul>
  </li>
  {% endfor %}
</ul>

1 Answer

Steven Parker
Steven Parker
210,425 Points

You're really close!

But courses isn't a method in itself. You could access it using the get method like you did with name, or you could just access it directly.

toirleachomalley
toirleachomalley
11,971 Points

wow, i thought I had tried that BUT I had a typo in the code when I did. Schoolboy error of having {$ instead of {% in one of jinja endfor tags. This is what I was trying to get at in relation to the debug or even better error messages coming from the quiz environment. It makes it very difficult to track down silly issues like this.

Thanks for the help. It is always good to get a second pair of eyes in the search.