html - 从带有烧瓶的for循环中显示的列表中将一些选定的项目保存到mysql
问题描述
我在一个使用flask的应用程序上,我检索了一个实体列表,因为没有分析我在表格中显示给用户的文本,这要归功于通过html文件的for循环,用户在验证返回的信息后,它必须验证并在数据库中保存一些数据并留下其他数据。我的问题是我无法管理批量验证,同一页面上的多个验证,因为它是在循环级别检索的单个变量。任何帮助将不胜感激。
代码烧瓶:
personEntities = (set([e.text for e in doc.ents if e.label_ == "PER"]))
locationEntities = list(set([e.text for e in doc.ents if e.label_ == "LOC"]))
organizationEntities = list(set([e.text for e in doc.ents if e.label_ == "ORG"]))
return render_template("extract_full.html", perso =personEntities, loca = locationEntities, orga = organizationEntities)
对于代码 HTML :
<table>
<tr>
<th>Entités</th>
<th>Categorie</th>
<th>Action</th>
</tr>
{% for personne in perso %}
<tr>
<td>
{{ personne }}
</td>
<td>Personne</td>
<td>
<form method="post">
<button type="submit" name = "person" class="btn waves-effect waves-light">Valider</button>
</form>
</td>
</tr>
{% endfor %}
</table>
为了保存在数据库中:
if request.method == "POST":
entite = ''
if (personEntities):
newPerson = Personne(nomFamile=personEntities)
db.session.add(newPerson)
db.session.commit()
解决方案
推荐阅读
- javascript - TypeError: Select is not a constructor when using Svelte and jest
- javascript - 承诺的 Vuex 模态?
- javascript - 在循环中使用 Node.js 中的 Axios 链接 API 请求 - 无法按顺序工作
- python - PySpark RDD:列数不匹配
- c# - 我应该如何设置一个在无限循环中执行慢速功能的计时器?(Winforms)
- jquery - chrome.runtime.onMessage.addListener 的异步性质导致在事件处理程序上使用变量时出现问题
- python - sklearn 验证分数含义
- svg - SVG 饼图仅适用于 Chrome,不适用于 Firefox
- swift - 使用 OpenKitten/BSON 包的“调用初始化程序没有完全匹配”
- javascript - 反转数组中的项目对