gpt4 book ai didi

python - WTForms RadioField 默认值

转载 作者:太空狗 更新时间:2023-10-29 17:32:52 25 4
gpt4 key购买 nike

我正在用这样的 wtforms 生成一个 html 表单:

<div class="control-group">
{% for subfield in form.time_offset %}
<label class="radio">
{{ subfield }}
{{ subfield.label }}
</label>
{% endfor %}
</div>

我的表单类是这样的:

class SN4639(Form):
time_offset = RadioField(u'Label', choices=[
('2', u'Check when Daylight saving has begun, UTC+02:00'),
('1', u'Check when Daylight saving has stopped, UTC+01:00')],
default=2, validators=[Required()])

当我现在打开编辑表单时,我通过 SQL 获得值 1 或 2 - 如何预设特定的单选按钮?

最佳答案

default=2 需要是字符串类型,而不是 int:

class SN4639(Form):
time_offset = RadioField(u'Label', choices=[
('2', u'Check when Daylight saving has begun, UTC+02:00'),
('1', u'Check when Daylight saving has stopped, UTC+01:00')],
default='2', validators=[Required()])

关于python - WTForms RadioField 默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16694121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com