Get text from text field in Flask

I would like to be able to write multiline text in textarea (HTML) and extract that text in python for processing using Flask. In addition, I would like to be able to write multi-line text in a form. I have no idea about using JS, so this will not help me. How should I do it?

+4
python html flask forms textarea
May 20 '16 at 11:12
source share
1 answer

Select a template with a form and a text box. Use url_for to specify the form in the view that will process the data. Access the data from request.form .

templates/form.html :

 <form action="{{ url_for('submit') }}" method="post"> <textarea name="text"></textarea> <input type="submit"> </form> 

app.py :

 from flask import Flask, request, render_template app = Flask(__name__) @app.route('/') def index(): return render_template('form.html') @app.route('/submit', methods=['POST']) def submit(): return 'You entered: {}'.format(request.form['text']) 
+8
May 20 '16 at 11:30
source share



All Articles