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 trialFareeza Khurshed
1,880 PointsFlask Basic - Nested Loops Challenge
Hi,
I'm having trouble with the nested loop question, though I think it's my code that's the issue.
I'm unsure of the structure of the "Teachers" file, I can't tell if its like the options files for this project or a similar Challenge/Task we did earlier where each teacher had a course list in a dictionary.
Could you clarify the structure of the teacher file? Any small hints on the answer is also appreciated, though I'd like the chance to work it through.
Thanks, Fareeza
from flask import Flask, render_template
from teachers import TEACHERS
app = Flask(__name__)
@app.route('/')
def index():
return render_template("teachers.html", teachers=TEACHERS)
<ul class="teachers">
{% for teacher in teachers: %}
<li><h2>{{ teacher['name'] }}</h2>
{% for course in teacher['courses']: %}
<li> {{ course }} </li>
{% endfor %}
</li>
{% endfor %}
</ul>
1 Answer
Mikael Enarsson
7,056 PointsI don't know if you already solved this, but the structure of the dict elements in the teachers list does seem to be a string name and a list of courses. That part of your code is fine.
The problem, and I made the same mistake when I tried to correct your code, is that you haven't wrapped the courses list in a second < ul > field (sorry about the spaces in the tag, I don't know how to get inline code...). To quote the challenge text: "Now add a new < ul > inside of the < li > with a class of 'courses'. ...".
I hope that this is of some help without giving away to much ^^
Fareeza Khurshed
1,880 PointsFareeza Khurshed
1,880 PointsThanks! Funny how reading the instructions helps :)
I find it hard to program to specs when you don't have a full view of what's going on.
Mikael Enarsson
7,056 PointsMikael Enarsson
7,056 PointsNo problem ^^ Not having all the specs probably is fairly common working in an environment where, to many people, computers are more or less magic, so some of the... let's call them more vague exercises are probably quite informative. On the other hand, since it seems that they often want you to solve a problem in a certain way, sometimes some more information would be helpful ><