我的formencode.variabledecode返回一个空列表 - Pylons

时间:2010-12-04 03:41:55

标签: python forms pylons formencode

HTML:

<input type="text" name="blah-0" value="test" />
<input type="text" name="blah-1" value="another test" />

控制器:

class myvalidator(formencode.Schema):

    allow_extra_fields  = True
    filter_extra_fields = True

    test = formencode.ForEach(formencode.validators.String())

def form_posted(self):
     form_result = myvalidator().to_python(request.params)

     print form_result

我想要的是返回一个列表。类似的东西:

> print form_result['blah']
['test', 'another test']

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您的示例不完整,但您必须先解码变量:

from formencode import variabledecode

def form_posted(self):
     decoded = variabledecode.variable_decode(request.params)
     form_result = myvalidator().to_python(decoded)
     print form_result

如果你想要等等,你也应该改变那一行:

test = formencode.ForEach(formencode.validators.String())

为:

blah = formencode.ForEach(formencode.validators.String())