Python 3.x 有没有办法在运行时以编程方式设置WTForm字段值?

Python 3.x 有没有办法在运行时以编程方式设置WTForm字段值?,python-3.x,wtforms,flask-wtforms,Python 3.x,Wtforms,Flask Wtforms,基本上,这为什么不会导致select选项有一个selected值 >>> import wtforms >>> class MyForm(wtforms.Form): ... choice = wtforms.SelectField('A Choice', choices=[(1, 'hi'), (2, 'there')]) ... >>> form = MyForm() >>> form.choice.d

基本上,这为什么不会导致
select
选项有一个
selected

>>> import wtforms
>>> class MyForm(wtforms.Form):
...     choice = wtforms.SelectField('A Choice', choices=[(1, 'hi'), (2, 'there')])
...     
>>> form = MyForm()
>>> form.choice.data = 2
>>> print(form.choice)
<select id="choice" name="choice"><option value="1">hi</option><option value="2">there</option></select>
>>导入wtforms
>>>类MyForm(wtforms.Form):
...     choice=wtforms.SelectField('A choice',choices=[(1,'hi'),(2,'there')]))
...     
>>>form=MyForm()
>>>form.choice.data=2
>>>打印(表单选择)
至此
看起来第二个
标记应该有一个
selected
属性


有没有办法在运行时设置WTF表单字段的值?

将其理解为WTF表单。是的。。。这是一个微不足道的项目名称。