Skip to content Skip to sidebar Skip to footer

How Do I Bind An Flask-wtform Unboundfield?

I am creating an app to post products to a marketplace. Each product category on this marketplace has a different form for product attributes, for example if it's electronic there

Solution 1:

To create a dynamic form with wtforms use the following template

defDynamicForm(*args, **kwargs):
    classStaticForm(FlaskForm):
        passif args[0] == True:
        StaticForm.class_attrib1 = StringField(...)
    else:
        StaticForm.class_attrib2 = StringField(...)

    return StaticForm()

This establishes a StaticForm within the local scope of the function, attaches all of the relevant items based on programming logic from the function arguments and returns an instantiated form:

form = DynamicForm(True)
# form has attribute: class_attrib1

This is explained in the docs somewhere, but I cant find the link right now

Post a Comment for "How Do I Bind An Flask-wtform Unboundfield?"