python - 烧瓶 form.data 值未在提交时更新
问题描述
我有一个表单,可以动态填充使用 .default 方法的值。
像这样:
for i, item in enumerate(staff):
if item.id == "csrf_token" or item.id == "submitstaff":
continue
item.default = stafftable[0][i]
staff.process()
我也使用了这个表格,没有这个过程,它可以工作。但是,当我在执行此过程后使用它时,它总是采用默认值,不允许用户再更新这些值。例如,如果我显示表单 agian 并尝试更改字段的值,它将采用进程设置的 .default 字段而不是输入。
形式:
class Staff(FlaskForm):
staffid = StringField(
validators=[DataRequired(message="Staff Id Field can not be left blank")]
)
Firstname = StringField(
validators=[DataRequired(message="Firstname Field can not be left blank")]
)
LastName = StringField(
validators=[DataRequired(message="LastName Field can not be left blank")]
)
ProjectRole = StringField(
validators=[DataRequired(message="ProjectRole Field can not be left blank")]
)
YearsOfExperience = FloatField(
validators=[
DataRequired(message="Years of experience Field can not be left blank")
]
)
Organisation = SelectField(
"Organisations",
choices=[
("1","1"),
("1","1"),
("1","1"),
],
)
OfficeLocation = StringField(
validators=[DataRequired(message="Office location Field can not be left blank")]
)
Discipline = SelectField(
"Discipline",
choices=[
("Geotechnics", "Geotechnics"),
("Civil", "Civl"),
("Digital", "Digital"),
("Project Management", "Project Management"),
],
)
KeyPersonName = SelectField(choices=[("No","No"),("Yes","Yes")])
BatchNo = StringField(
validators=[DataRequired(message="BatchNo Field can not be left blank")]
)
ProjectStatus = StringField(
validators=[DataRequired(message="ProjectStatus Field can not be left blank")]
)
Booking = StringField(
validators=[DataRequired(message="Booking Field can not be left blank")]
)
TasksEarlyDeliverables = TextAreaField(
validators=[
DataRequired(
message="Tasks and early deliverables Field can not be left blank"
)
]
)
requester = StringField()
package = StringField()
PercentoftimeS1 = FloatField()
HourlyRate = FloatField()
PercentoftimeS2 = FloatField()
submitstaff = SubmitField(label="Submit", validators=[DataRequired()])
解决方案
因此,经过一番研究,我发现使用 .process 会导致它无法正常工作。但是,使用上面的代码而不使用 .process 它不会在网页上显示数据。
显示数据的解决方案实际上是使用 .data 而不是 .default。
推荐阅读
- javascript - jQuery 动画应该在悬停时暂停
- google-cloud-platform - 尝试访问 http://metadata.google.internal 时出现连接被拒绝错误
- tensorflow - per_process_gpu_memory_fraction 没有后果?
- php - 如何使用 php 创建 XML 输出?
- flutter - Flutter“无法加载资产”错误,尽管一切看起来都不错
- google-sheets - Google 表格按今天日期过滤
- pandas - 如何在 pivot_table 上有小计?(已经有边距= True)
- highcharts - Highcharts 每个节点的自定义符号和颜色
- c++ - 如何从头开始实现 EventSource (SSE) 服务器端?
- c# - 在 Visual Studio 中编辑的 Unity 脚本在某些行上不提供自动完成功能