1

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']

我究竟做错了什么?

4

1 回答 1

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())
于 2010-12-05T18:45:30.540 回答