WTForms BooleanField 可以有自定义值吗?

Can a WTForms BooleanField have a custom value?

我想使用 WTForms(实际上是 Flask-WTF)来生成这个:

<input id="attr" name="attr" type="checkbox" value="ALL"> Include all attributes

但是如果有任何方法可以指定一个值作为 BooleanField 的一部分,我找不到它。如果我指定:

class MyForm(Form):
    attr = BooleanField('attr', default=False, description="Include all attributes")

并在模板中渲染它:

{{ form.attr }} {{ form.attr.description }}

然后我得到

<input id="attr" name="attr" type="checkbox" value="y"> Include all attributes

BooleanField 没有要设置的 "choices" 或 "value" 属性。有没有办法强制它具有我选择的值(例如 ALL)而不仅仅是 y

Booleanfield 只能将值属性设置为 True 或 False。

SelectFieldRadioField 可用于设置具有自定义值的复选框。

class TestForm(Form): 
    Attr_field = SelectField("Attr ", choices=[("ALL", "label")], default="ALL")

使用 SelectMultipleField 设置复选框列表并全部填充。