• webpy form


    原文http://webpy.org/form

    import web from web import form render = web.template.render('templates/') urls = ('/', 'index') app = web.application(urls, globals()) 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) if __name__=="__main__": web.internalerror = web.debugerror app.run()

    And sample formtest.html (place this in the templates subdirectory):

    $def with (form)
    
    <form name="main" method="post"> 
    $if not form.valid: <p class="error">Try again, AmeriCAN:</p>
    $:form.render()
    <input type="submit" />    </form>
  • 相关阅读:
    Documents
    gitlab 安装和配置
    git相关知识
    马俊龙ansible教程分享
    源码安装python 报错,openssl: error while loading shared libraries: libssl.so.1.1
    jumpserver 常见错误解决
    nginx 定义:响应头和请求头
    gcc入门(下)
    gcc入门(上)
    awk命令
  • 原文地址:https://www.cnblogs.com/banwhui/p/4600567.html
Copyright © 2020-2023  润新知