WTforms QuerySelectField,SelectField,MultipleSelectField似乎不适用于validate_on_submit()

时间:2018-07-04 07:09:12

标签: python flask flask-wtforms wtforms

所以我有一个带有QuerySelect字段和String字段的表单。当我尝试提交它并在服务器端对其进行验证时,它只是没有发生。 POST请求正在处理正确的数据,但从不输入if form.validate_on_submit()。我为此感到疯狂,将不胜感激。

如果我删除了SelectFields,表单也可以验证。在下面的示例中,我正在使用MultipleSeletField

这是代码:

这是我的路线逻辑:

app.py

waiver()

model.py:

 @app.route('/contacts' , methods=['GET' , 'POST'])
 @login_required
 def contacts():
        '''
            Add contacts to database with option to export 
            and import data onto Peep.
        '''
        user = current_user.username 
        form = login_model.AddContactForm()
        form_add_group = login_model.AddGroupForm()
        form_add_group.contact.choices = [ (r.id , r.company_name ) for r in login_model.AddContact.query.order_by('company_name') ]

        if form_add_group.validate_on_submit():
            print("going in")
            return "{}{}".format(form_add_group.group.data , form_add_group.contact.data)

        mssg = ""
        contact_list = db.session.query(login_model.AddContact).all() 




        return render_template('contacts.html' , user = user ,form = form , error_mssg_a ="Testing the error run" ,
        contact_list = contact_list , form_add_group=form_add_group) , 200

这是模板:

class AddGroupForm(FlaskForm):
    group = QuerySelectField('group' , allow_blank = False , get_label = 'group' , query_factory = group_choice)
    contact= SelectMultipleField('contact' )

0 个答案:

没有答案