所有 web.py 表单示例都采用以下格式(来自 webpy.org):
myform = form.Form(
form.Textbox("boe"),
form.Textbox("bax",
form.notnull,
form.regexp('\d+', 'Must be a digit'),
form.Validator('Must be more than 5', lambda x:int(x)>5)),
form.Textarea('moe'),
form.Checkbox('curly'),
form.Dropdown('french', ['mustard', 'fries', 'wine']))
class index:
def GET(self):
form = myform()
# make sure you create a copy of the form by calling it (line above)
# Otherwise changes will appear globally
return render.formtest(form)
def POST(self):
form = myform()
if not form.validates():
return render.formtest(form)
else:
# form.d.boe and form['boe'].value are equivalent ways of
# extracting the validated arguments from the form.
return "Grrreat success! boe: %s, bax: %s" % (form.d.boe, form['bax'].value)
我不想在声明表单时填写静态下拉框(上例中的 form.Dropdown),而是在调用页面时使用从数据库表中检索到的条目的 GET/POST 方法。
我已经搜索了几个小时,但在任何地方都找不到提示(google、webpy.org、google groups)