how to check which submit button is clicked in flask wtf

Solutions on MaxInterview for how to check which submit button is clicked in flask wtf by the best coders in the world

showing results for - "how to check which submit button is clicked in flask wtf"
Martina
03 Mar 2019
1from flask import Flask, render_template, redirect, url_for
2from flask_wtf import Form
3from wtforms import SubmitField
4
5app = Flask(__name__)
6app.secret_key = 'davidism'
7
8class StatsForm(Form):
9    user_stats = SubmitField()
10    room_stats = SubmitField()
11
12@app.route('/stats', methods=['GET', 'POST'])
13def stats():
14    form = StatsForm()
15
16    if form.validate_on_submit():
17        if form.user_stats.data:
18            return redirect(url_for('user_stats'))
19        elif form.room_stats.data:
20            return redirect(url_for('room_stats'))
21
22    return render_template('stats.html', form=form)
23
24app.run(debug=True)