Python 金字塔 - 如何使用复选框和单选按钮 [英] Python pyramid - How to use checkboxes and radio buttons
问题描述
我一直在尝试使用 Pyramid 框架制作一个带有复选框和单选按钮的表单,但我不知道如何正确地做到这一点.
I've been trying to make a form with checkboxes and radio button using Pyramid framework but I can't figure out how to do it properly.
我正在使用 pyramid_simpleform
.到目前为止,我已经能够使用 for 循环将复选框放在表单上,但即使指定 checked=True
,我也无法选中任何复选框.
I'm using the pyramid_simpleform
. So far I've been able to put my checkboxes on the form using a for loop but I can't make any checkbox checked even if I specify checked=True
.
% for item in groups:
${form.checkbox(name="groups",label=item, value=item, checked=True)}
% endfor
我知道有更好的方法来做到这一点.有没有我可以看的例子.金字塔文档中的所有示例都是简单的文本字段.到目前为止,我没有找到任何单选按钮或复选框.
I know there's a better way of doing this. Is there any examples I could look at. All the examples in pyramid's documentation are simple text fields. I didn't find any radio button or checkboxes so far.
推荐答案
你试过把
defaults={"groups" : True}
例如在 Form ctor 中(在 pyramid_simpleform 文档中):
in Form ctor, for example (in pyramid_simpleform doc):
form = Form(request, MySchema, defaults={"name" : "foo"})
这篇关于Python 金字塔 - 如何使用复选框和单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!