Infinity8
Infinity8

Reputation: 705

List converted to Dropdown in Flask/WTForms

Basically I have a list in Python and would like to programmatically call on and create a dropdown form from this list using WTForms into an HTML doc. I can't figure out what I am missing here when trying to use the SelectField approach in WTForms. The list is within "updatef".

I get the error: ValueError: need more than 1 value to unpack when trying to run this.

class ReusableForm(Form):  # Define the form fields and validation parameters
    updates = SelectField(u'Update Frequency', choices = updatef, validators = [validators.required()])


@app.route("/editor", methods=['GET', 'POST'])
def hello():
    form = ReusableForm(request.form)  # calls on form

        if request.method == 'POST':
            updates = request.form['updates']

HTML

    <form  id="main" action="" method="post" role="form" spellcheck="true">
    <p> {{ form.updates }} </p>

Upvotes: 1

Views: 3855

Answers (1)

Matt Healy
Matt Healy

Reputation: 18531

choices has to be a list of 2 value tuples such as [(1,'Daily'),(2,'Weekly')] - your error seems to suggest you might only have a list of values.

Upvotes: 1

Related Questions