Retrieve Text From Textarea In Flask
I would like to be able to write a multi-line text in a textarea (HTML), and retrieve this text in python for processing using Flask. Alternatively, I would like to be able to writ
Solution 1:
Render a template with the form and textarea. Use url_for
to point the form at the view that will handle the data. Access the data from request.form
.
templates/form.html
:
<formaction="{{ url_for('submit') }}"method="post"><textareaname="text"></textarea><inputtype="submit"></form>
app.py
:
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')defindex():
return render_template('form.html')
@app.route('/submit', methods=['POST'])defsubmit():
return'You entered: {}'.format(request.form['text'])
Post a Comment for "Retrieve Text From Textarea In Flask"