本文介绍了WTForms“太多值以至于无法解包".与SelectField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WTForms,并且试图显示SelectField,但是出现以下错误:

I'm using WTForms and I'm trying to display a SelectField, but I get the following error:

>>> form.status()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\Lib\site-packages\wtforms\fields.py", line 136, in __call__
    return self.widget(self, **kwargs)
  File "C:\Python26\Lib\site-packages\wtforms\widgets.py", line 237, in __call__
    for val, label, selected in field.iter_choices():
  File "C:\Python26\Lib\site-packages\wtforms\fields.py", line 390, in iter_choices
    for value, label in self.choices:
ValueError: too many values to unpack

这是我的表格:

class TestForm(Form):
    status = SelectField(u'Status', choices=Test.statuses())

Test.statuses静态方法返回字符串列表.我在做什么错了?

The Test.statuses static method returns a list of strings. What am I doing wrong?

推荐答案

它需要一个(str, str)元组的列表,而不是字符串的列表.

It expects a list of (str, str) tuples, not a list of strings.

这篇关于WTForms“太多值以至于无法解包".与SelectField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 14:43