简体   繁体   中英

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>

choices必须是2个值元组的列表,例如[(1,'Daily'),(2,'Weekly')] -您的错误似乎表明您可能只有一个值列表。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM