2

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 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.