Python Flask Basics Character Builder Items

Jacob Murphy
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jacob Murphy
Full Stack JavaScript Techdegree Graduate 31,711 Points

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!

Myers Carpenter
Myers Carpenter
Treehouse Staff

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.

Jacob Murphy
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jacob Murphy
Full Stack JavaScript Techdegree Graduate 31,711 Points

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">

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

Jacob Murphy
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jacob Murphy
Full Stack JavaScript Techdegree Graduate 31,711 Points

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.