python - Flask 从带有文本区域的表单输入数据
问题描述
我想从 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>
在烧瓶中,我有以下路线:
@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!')
我想用从HTML 中sequences
的标记输入的数据替换 POST 方法上的硬编码变量 。textarea
谢谢你的帮助!
解决方案
你可以添加这个。
索引.html
<textarea name="form-text" id="text" cols="30" rows="15" placeholder="Insert the post here">
应用程序.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!')
推荐阅读
- apache - Apache 和 Yarn 端口
- c - 调试了几个小时,分段错误。找不到问题
- javascript - HTML 元素在导航到页面时消失,在页面刷新时重新出现
- python - 将 wav 文件转换为图像并再次转换回来
- python - matplotlib中直方图绘制的基本问题
- javascript - 用 javascript 中的 post 方法在 location.replace 中发送数据
- tensorflow - 隐藏状态张量的顺序与返回的张量不同
- r - 在分组数据条件下为唯一 ID 创建变量
- python - 如何使用 Python 抓取嵌入在网站中的表格
- swift - 确定 NSCollectionViewCompositionalLayout 的部分标识符