-2

I want to input data (text area) from the html file and process it in Python, i made a form like so:

<form action="/" method="post">
    <div class="postText">
    <textarea name="" id="text" cols="30" rows="15" placeholder="Insert the post here">

    </textarea>
    </div>

    <button type="submit">Go!</button>
    </form>

In Flask I have the following route:

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        sequences = ['This is a gaming sentence']
        prediction = clf.predict(sequences)[0].title()
        return render_template('index.html', prediction=prediction)
    else:
        return render_template('index.html',
                               prediction='Predictions will appear here!')

I want to replace the hardcoded sequences variable on the POST method with the data inputted from the textarea tag in the HTML.

Thanks for any help!

orie
  • 541
  • 6
  • 20

1 Answers1

0

You could add this.
index.html

<textarea name="form-text" id="text" cols="30" rows="15" placeholder="Insert the post here">

app.py

@app.route('/', methods=['GET', 'POST'])
def index():
    sequences = ['This is a gaming sentence']
    if request.method == 'POST':
        sequences = request.form.get("form-text")
        prediction = clf.predict(sequences)[0].title()
        return render_template('index.html', prediction=prediction)
    else:
        return render_template('index.html',
                               prediction='Predictions will appear here!')
vnk
  • 1,060
  • 1
  • 6
  • 18