如何从 WTForms 中的 SelectField 获取值(非键)数据

How to get value (not key) data from SelectField in WTForms

我有一个 WTF SelectField,我正在尝试存储用户选择的名称以在另一个页面上显示。

鉴于我的表格是

choice = SelectField('Choice', choices=[('cho_1', 'Choice One'), ('cho2', 'Choice Two')])

我明白

self.choice = form.choice.data

会让我得到用户的选择(比如 cho_1),但是我如何获得 ("Choice One")?我觉得这对听写来说很简单,但是各种尝试加上 googling/searching 到目前为止还没有帮助。

感谢Ashish Nitin Patil for directing me to here

我需要将 'choices' 转换为字典,然后获取键 form.data 的值,因此:

 value = dict(form.choice.choices).get(form.choice.data)