Flask 提交表格1,但不提交烧瓶中的表格2
若我提交表格1,则表格2将自动提交,表格2的空白值存储在数据库中Flask 提交表格1,但不提交烧瓶中的表格2,flask,sqlite,multiple-forms,Flask,Sqlite,Multiple Forms,若我提交表格1,则表格2将自动提交,表格2的空白值存储在数据库中 @app.route('/profile', methods=['POST', 'GET']) @login_required def profile(): form1 = ProfileForm1() form2 = ProfileForm2() if form1.validate_on_submit() and request.method=='POST': profile = Profile.query.filter
@app.route('/profile', methods=['POST', 'GET'])
@login_required
def profile():
form1 = ProfileForm1()
form2 = ProfileForm2()
if form1.validate_on_submit() and request.method=='POST':
profile = Profile.query.filter_by(id=current_user.id).first()
profile.name=form1.name.data
profile.contact = form1.contact.data
flash('Profile UPDATED (refresh to see update)')
if form2.validate_on_submit() and request.method =='POST':
profile = Profile.query.filter_by(id=current_user.id).first()
profile.position = form2.position.data
profile.address = form2.address.data
flash("Updated - refresh to see")
items = Profile.query.filter_by(id=current_user.id).first()
return render_template("profile.html", form1=form1,form2=form2,item=items)
ProfileForm1和ProfileForm2都有相同的数据库
注意:配置文件表是在代码的其他部分中创建的
编辑:我将两个表单的验证器都更改为InputRequired(),这对我来说很有效。如果你想在一个页面上处理两个表单,最简单的方法是在服务器上为它们创建单独的发布路径。thanx:)这对我来说很有效。