2

在 Pylons 1 中使用过形式化学之后,我正在使用pyramid_simpleform迈出第一步。

我开始使用的表单非常简单:我有一些选项,用户必须检查一个。

这里的表单类:

class OptionsSchema(Schema):
    ...
    id_opt = validators.Int(not_empty=True)

这是视图中的实例:

model = DBSession.query(models.Model).first()
form = Form(request, schema=OptionsSchema, obj=model)
renderer = FormRenderer(form)

比方说model.id_opt == 3

在这里,我为模板option中的每个单选按钮:model

%for opt in model.options:
    ${form.radio('id_opt', value=opt.id)}
%endfor

我期望看到的是checked="checked"这样id_opt == 3的:

<input id="id_opt_1" name="id_opt" type="radio" value="1" />    
<input id="id_opt_2" name="id_opt" type="radio" value="2" />    
<input id="id_opt_3" checked="checked" name="id_opt" type="radio" value="3" />    

但我没有。

我必须自己设置检查选项吗?

4

0 回答 0