Python Flask WTForms:如何在视图中动态禁用字段?
I've been able to implement this change to create Field which is disabled in WTForms. How would I selectively disable a field in my view before rendering it?
我已经能够实现此更改以创建在WTForms中禁用的Field。在渲染之前,如何有选择地禁用视图中的字段?
3 个解决方案
#1
8
If you're trying to remove a field you could look at the Removing Fields Per-instance in the documentation.
如果您尝试删除字段,可以查看文档中的“每个实例删除字段”。
From the docs:
来自文档:
Sometimes, you create a form which has fields that aren’t useful in all circumstances or to all users. While it is indeed possible with form inheritance to define a form with exactly the fields you need, sometimes it is necessary to just tweak an existing form. Luckily, forms can have fields removed post-instantiation by using the del keyword:
有时,您创建的表单包含在所有情况下无用的字段或所有用户。虽然确实可以使用表单继承来定义具有所需字段的表单,但有时需要调整现有表单。幸运的是,表单可以在实例化后使用del关键字删除字段:
class MagazineIssueForm(Form):
title = TextField()
year = IntegerField('Year')
month = SelectField(choices=MONTHS)
def edit_issue():
publication = get_something_from_db()
form = MagazineIssueForm(...)
if publication.frequency == 'annual':
del form.month`
更多相关文章
- FieldErro:无法将关键字'date_added'解析为字段。选项包括:data_ad
- Django -表单无效但没有错误
- 如何在/account / url模式之外使用Django-AllAuth注册表单?
- Oracle表按字段和|分格符导出文件
- 是否遇到过MySQL workbench text字段不能直接放入json格式内容
- 求sql【复制同一表记录,但有两个字段需要修改--详情 Btn_oncliek
- 查询表中的某一行,表中没有行号相关的属性字段,SQL语句怎么写啊?50
- SQL根据某个字段分组查询:
- mysql中如何对text字段值进行追加更新