Python Flask Basics Character Builder Looping Through Items

peterbristow
peterbristow
10,403 Points

Please help me with this question?

This is what I tried: <ul> {% for item, keys in options.items() %} {% for key in keys %} {% if item[key] == 'name' %} {{ key }} {% endif %} {% endfor %} {% endfor %} </ul>

Please let me know what is wrong with it?

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)
templates/options.html
<ul>
  {% for item, keys in options.items() %}
    {% for key in keys %}
      {% if item[key] == 'name' %}
        {{ key }}
      {% endif %}
    {% endfor %}
  {% endfor %}
</ul>

1 Answer