how to check which submit button is clicked in flask wtf

from flask import Flask, render_template, redirect, url_for
from flask_wtf import Form
from wtforms import SubmitField

app = Flask(__name__)
app.secret_key = 'davidism'

class StatsForm(Form):
    user_stats = SubmitField()
    room_stats = SubmitField()

@app.route('/stats', methods=['GET', 'POST'])
def stats():
    form = StatsForm()

    if form.validate_on_submit():
        if form.user_stats.data:
            return redirect(url_for('user_stats'))
        elif form.room_stats.data:
            return redirect(url_for('room_stats'))

    return render_template('stats.html', form=form)

app.run(debug=True)

Here is what the above code is Doing:
1. We created a form class called StatsForm.
2. We created a view function called stats.
3. We created a route for the stats view function.
4. We created a template called stats.html.
5. We created a view function called user_stats.
6. We created a view function called room_stats.
7. We created a route for the user_stats view function.
8. We created a route for the room_stats view function.