Give your two buttons the same name and different values:
<input type="submit" name="submit_button" value="Do Something">
<input type="submit" name="submit_button" value="Do Something Else">
Then in your Flask view function you can tell which button was used to submit the form:
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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…