【发布时间】:2021-12-04 19:59:04
【问题描述】:
我想从 html 文件中输入数据(文本区域)并在 Python 中处理它,我做了一个这样的表格:
<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>
在 Flask 中,我有以下路线:
@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!')
我想将 POST 方法中硬编码的 sequences 变量替换为 HTML 中 textarea 标记输入的数据。
感谢您的帮助!
【问题讨论】:
标签: python html forms flask textarea