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 trial

Python Flask Basics Character Builder Looping Through Items

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

Dont know HTML have no clue what im doing in flask.

First question. Is this homework trying to get me to make a list before I start running a for loop through it?

Second... am I doing the html portion right by simply opening and closing a list <li></li>?

Third... is this for loop correct? I've also tried print dict(option.items())['name'].

app.py
from flask import Flask, render_template

from options import OPTIONS

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('options.html', options=OPTIONS)

for option in OPTIONS:
    print option.items()[0]
templates/options.html
<ul>
<li>
  </li>
</ul>

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! The code challenge is asking you to use a Flask templating for loop. It wants you to loop through the options being passed into the template inside of the index function. All you need to do is create the loop notation inside of the HTML file, so you don't need to add anything to the python file app.py.

The video before this code challenge shows an example of writing the for loop at the beginning. Here are some examples from the documentation too.

I also highly suggest checking out the prerequisites for this course if you haven't already. They include some HTML courses.

Andy Hughes
Andy Hughes
8,478 Points

At around 3:43 in the video actually shows an example that is closer to the format asked for in the challenge. The bit I couldn't figure out and still can't is why I couldn't write {{ option }} and get the result. Instead I had to write it as {{ option.name }}. That is not covered or explained in the video.

I figure it's just the teacher trying to confuse us even more than he already has :P