jinja2 loop over flask wt-form

Viewed 578

loop over form.someinput with jinja

I want to use the jinja for loop but also use wtforms in the same loop The for loop goes over the dictionary keys the wtforms has the is the same as the keys

privesly I have done this:

    {% for key in dict.items() %}
        <label for="">{{ key }}:</label>
        <input type="text" name="" value="" class="">
    {% endfor %}

But I want to use WTForms.

I want to do something like this, but it dose not work when I try

    {% for key in dict.items() %}
          {{ form.key.label }}
          {{ form.key(class="form-control") }}
    {% endfor %}

Soe can I loop over WTForms with jinja?

1 Answers

As you have the name of the form field in the key variable, you need to use form[key] instead of form.key. Otherwise you are trying to access a field named 'key' that does not exists in all the iterations of your loop.

Related