为两个按钮指定相同的名称和不同的值:
<input type="submit" name="submit_button" value="Do Something"><input type="submit" name="submit_button" value="Do Something Else">
然后,在Flask视图函数中,您可以知道使用了哪个按钮来提交表单:
def contact(): if request.method == 'POST': if request.form['submit_button'] == 'Do Something': pass # do something elif request.form['submit_button'] == 'Do Something Else': pass # do something else else: pass # unknown elif request.method == 'GET': return render_template('contact.html', form=form)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)