python - FlaskWTF 多个表单相同的页面,带有 1 个提交按钮
问题描述
我正在尝试创建一些东西,用户可以在其中将选定数量的人添加到数据库中。唯一(现在)被问到的是人名。
我通过执行以下操作创建此表单:
<form method="post" action="{{ url_for('add_person') }}">
{{ form.csrf_token }}
{% for i in range(0, amount) %}
{{ form.plafond.label }}
{{ form.plafond }}
</br>
{% endfor %}
<input type="submit" value="Submit">
</form>
和:
class new_person(FlaskForm):
name = StringField('Name')
如何获取此人在每个字段中输入的个人数据?
解决方案
您需要在表单中添加这些字段,假设它们是字符串(更改您使用的数据类型)
class new_person(FlaskForm):
name = StringField('Name')
csrf_token =StringField('csrf')
然后在提交时通过(在您的 add_person 方法中)访问它:
form = new_person()
form.csrf.data # This will give you the csrf data
推荐阅读
- spring-boot - EntityManager 与 Spring Data JPA 的存储库
- spring - 使用 Criteria 查询数组列是否包含
- python - Selenium Python ActionChain 不工作(不可交互元素)
- r - 在尊重可变对比度编码的同时,如何使用 anova() 对 lm 和 lmer 对象进行显着性测试?
- python - Python 字典 - 如何将多个值作为字符串返回
- arrays - 无法获得每个学生的姓名和年龄。相反,我得到了奇怪的字符和年龄 = 0?
- python - 如何使用 df.column.str.contains() 获得与下面代码相同的结果?
- questdb - questdb: 插入数据时经常显示Table Busy
- javascript - 将带逗号的输入数字转换为数字以执行计算,然后用逗号返回输出?
- java - 片段内的片段不能与 ScrollView 一起使用