wtforms FieldList&& amp;验证

时间:2011-06-18 11:02:44

标签: python wtforms

wtforms FieldList&& amp;验证... 应该说该字段必须具有Int值,而不是该字段是必需的 为什么f.data有[None,2,None]值,而不是['def',2,'abc']?

from webob.multidict import MultiDict

from wtforms import Form
from wtforms import FieldList, IntegerField
from wtforms import validators

class SearchForm(Form):
    locality_id = FieldList(IntegerField(u'Locality', [validators.Required()]))


d = MultiDict([('locality_id-0', 'def'), ('locality_id-1', 2), ('locality_id-2', 'abc')])

f = SearchForm(d)

print f.validate()
print f.errors
print f.data
print f.locality_id.data

%python form_test.py

{'locality_id':[[你需要这个字段。'],[你需要这个字段。']]}

{'locality_id':[无,2,无]}

[无,2,无]

1 个答案:

答案 0 :(得分:1)

看起来try... except祖先中有一个IntegerField块会将所有非整数放入process_errors属性,并且特别禁止该类允许您拥有数据填充了除有效数据之外的任何内容。不过,我相信您仍然可以在raw_data属性中获得所需的值。