Answers for "print text after submit button is pressed in flask"

5

button in flask

<input type="submit" name="submit_button" value="Do Something">
<input type="submit" name="submit_button" value="Do Something Else">
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)
Posted by: Guest on May-15-2020
1

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)
Posted by: Guest on June-16-2020

Code answers related to "print text after submit button is pressed in flask"

Python Answers by Framework

Browse Popular Code Answers by Language