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`

更多相关文章

  1. FieldErro:无法将关键字'date_added'解析为字段。选项包括:data_ad
  2. Django -表单无效但没有错误
  3. 如何在/account / url模式之外使用Django-AllAuth注册表单?
  4. Oracle表按字段和|分格符导出文件
  5. 是否遇到过MySQL workbench text字段不能直接放入json格式内容
  6. 求sql【复制同一表记录,但有两个字段需要修改--详情 Btn_oncliek
  7. 查询表中的某一行,表中没有行号相关的属性字段,SQL语句怎么写啊?50
  8. SQL根据某个字段分组查询:
  9. mysql中如何对text字段值进行追加更新

随机推荐

  1. android api 中文 (73)—— AdapterView
  2. Android开发指南-用户界面-事件处理
  3. Android上超级好用的前端调试方法(adb rev
  4. DeskSMS 在電腦收發、回覆 Android(安卓)
  5. Android(安卓)入门第十讲02-广播(广播概述
  6. 移动系统后起之秀渐露颓势:谷歌兄,拉Andr
  7. Notification中更新进度条
  8. android windows下开发环境搭建
  9. Android离线地图
  10. Android(安卓)Studio连接真机没反应