码迷,mamicode.com
首页 > Web开发 > 详细

webpy form

时间:2015-06-25 19:28:43      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

原文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>

webpy form

标签:

原文地址:http://www.cnblogs.com/banwhui/p/4600567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!