'Flask WTF Form: FieldList returns Empty UL

I'm new to Flask and I'm having an issue with WTF forms. I followed a simple tutorial to use FieldList to loop on the values and create a dynamic form. The FieldList returns as an empty ul id="Inventory" when I check it in the inspector. Any idea on what's wrong here? Thanks for any help.

FORM MODULE:

from flask_wtf import FlaskForm
from wtforms import StringField, FieldList, FormField, PasswordField, SubmitField, Form
from wtforms.validators import DataRequired

class InventoryForm(FlaskForm):
  Sku = StringField("What's your name", validators=[DataRequired()])
  password = PasswordField("Give me your password", validators=[DataRequired()])


class InventoryField(FlaskForm):
  Inventory = FieldList(FormField(InventoryForm))
  submit = SubmitField("Submit")

PYTHON CODE

@app.route('/', methods=["POST", "GET"])
def index():
  form = InventoryField()
  return render_template("test.html", form = form)

====HTML CODE====

<form method="POST">
  {{form.csrf_token}}
  {% for field in form.Inventory %}
    <h1>{{field}}</h1>
  {% endfor %}
</form>

I checked some videos and all the tutorials seemed to nest the forms as I did, same goes for the HTML code and the initialisation of the form in the Route, I am at a loss.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source