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 Items

Items not appearing

I'm having some trouble while following along in making the items show up on the builder page. here's my code:

{%for category, chices in options.items()%}
            {%if category !='colors'%}
                <div class="grid-100 row">
                    <div class="grid-20">
                        <p class="category-title">{{ category.title() }}</p>
                    </div>
                    <div class="grid-80">
                        <input type = "radio" id = "no_{{category}}_icon" name = "{{category}}" value='' {%if not saves.get(category)%}checked{%endif%}>
                        <label for = "no_{{category}}_icon">
                            <img src="/static/img/no-selection.svg">
                        </label>
                        {%for choice in choices%}
                            <input type="radio" id="{{category}}-{{choice}}_icon" name="{{category}}" value="{{choice}}" {% if saves.get(category) == choice %}checked{% endif %}>
                            <label for = "{{category}}-{{choice}}_icon">
                                <img src="/static/img/{{ category }}-{{ choice }}.svg">
                            </label>
                        {%endfor%}
                    </div>
                </div>
            {%endif%}
            {%endfor%}

Thanks in advance for any help!

It's unclear what's going wrong w/o building a Flask app and pasting in your code. You might have more luck getting answers if you answer these questions each time.

  1. What did you do?
  2. What did you expect it to do?
  3. What did it actually do?

I understand the "what did you do?" part, you have a good code sample. But I don't understand what you thought it would do and what it actually do.

Hey Myers, thanks for the tip! To answer your question. I thought or purposed the code to make the different items for the courses' web-app bear builder appear. What it done was nothing. Everything does as its suppose to do up until the {%for choice in choices%} code block, then it doesn't do anything.

2 Answers

You currently have the first line of what you pasted there as:

{%for category, chices in options.items()%}

There's a typo in 'choices', so try change the line to the following:

{%for category, choices in options.items()%}

That's why the category part worked. It got passed to the Flask/Jinja template code as expected. But when you go to the loop of {%for choice in choices%}, it couldn't find choices, so it just ignored the whole block.

Be careful with your HTML formatting too, attributes shouldn't have a space between the attribute name, the equals sign, and the quotes around the value. It should be, for example:

<input type="radio">

That typo seemed to be it! Thanks a bunch for pointing that out.

Show your question in HTML section *here is the python language !

Hey there! We're using the Flask Framework in this course, so in the HTML anything inside either double curly braces {{}} or curly braces and percentages {%%} is python code or objects.