You can get form data from Flask's request object with the form
attribute:
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
data = request.form['input_name'] # pass the form field name as key
...
You can also set a default value to avoid 400 errors with the get()
method since the request.form
attribute is a dict-like object:
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
default_value = '0'
data = request.form.get('input_name', default_value)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With