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
204,000 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.