Flask-WTF没有获得选择字段值

时间:2019-01-26 13:11:58

标签: python flask flask-wtforms wtforms

这是我用来创建表单的代码

class ReusableForm(Form):
    c = SelectField('COLOR', choices=[])
    r = SelectField('RATING', choices=[])
    s = SelectField('SIZE', choices=[])
    v = SelectField('VERIFIED', choices=[])
    senti = TextField('SENTIMENT LEVEL:', validators=None)

应用路线页面

@app.route('/', methods=['GET', 'POST'])
def home():
    form = ReusableForm(request.form)
    """Get all Filtering attributes we need"""
    form.c.choices = list(set((i['Colour'], i['Colour']) for i in inputFile))
    form.r.choices = list(set((i['Rating'], i['Rating']) for i in inputFile))
    form.s.choices = list(set((i['size'], i['size']) for i in inputFile))
    form.v.choices = list(set((i['Verification'], i['Verification']) for i in inputFile))

    if request.method == 'POST':
        color = request.form['c']
        rating = request.form['r']
        size = request.form['s']
        v = request.form['v']
        senti = request.form['senti']

        print(color)

    return render_template('home.html', form=form)

html是

<div class="row">
      <div class="col s2"></div>
           <div class="col s8">
                <form method="POST">
                        {{form.csrf}}
                        {{form.c}}
                 </form>
             </div>
        <div class="col s2"></div>
</div>

当我尝试打印color时,它不在控制台中打印。

0 个答案:

没有答案