小编ram*_*yne的帖子

如何使用web.py动态填充表单中的选择框/下拉框?

所有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 …
Run Code Online (Sandbox Code Playgroud)

python forms web.py

6
推荐指数
1
解决办法
3216
查看次数

标签 统计

forms ×1

python ×1

web.py ×1