Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

PREVIOUS NEXT
Code Example
Python :: how to print x in python 
Python :: pyspark check all columns for null values 
Python :: seaborn correlation 
Python :: how to add element at first position in array python 
Python :: django drop database postgres 
Python :: create text file in directory python linux 
Python :: remove all integers from list python 
Python :: pandas set condition multi columns 
Python :: delete the content from the entry form in tkinter python 
Python :: python xml replace attribute value 
Python :: port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections? 
Python :: Python make directories recursively 
Python :: django creating calculated fields in model 
Python :: python ftp login 
Python :: reverse text python 
Python :: merge two dict python 3 
Python :: how to import a python function from another file 
Python :: how to practise python 
Python :: pandas reset index without adding column 
Python :: np deep copy matrix 
Python :: how to use regex in a list 
Python :: python change terminal name 
Python :: ym ip 
Python :: how to get elasticsearch index list using python 
Python :: packing and unpacking in python 
Python :: nlargest heapq 
Python :: flip key and value in dictionary python 
Python :: path of current working directory with os module python 
Python :: impute mode pandas 
Python :: sqlite check if table exists 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =