webpy 简单表单一粒

 

# -*- coding: gbk -*-
import web
from web import form
urls=('/jg','jg',)
app=web.application(urls,globals())
render = web.template.render('templates') # your templates

vweight = form.regexp(r"[0-9]{1,2}", 'must be a shuzhi')
vage = form.regexp(r"[0-9]{1,2}", "must be a valid age")
vjigan = form.regexp(r"[0-9]{1,2}", "must be a valid age")

jg_form = form.Form(
    form.Textbox("weight",vweight, description="weight "),
    form.Textbox("age", vage, description="age"),
    form.Textbox("jigan", vjigan, description="jigan"),
    form.Radio("sex",["female","male"]),
    form.Button("submit", type="submit", description="submit"),
)

class jg:
    def GET(self):
        # do $:f.render() in the template
        f = jg_form()
        #return f
        return render.jigan(f)

    def POST(self):
        f = jg_form()
        postdata=web.input()
        if not f.validates():
            #return render.jigan(f)
            #return "hello"
            #postdata=web.input()
            return 'hhh'
        else:
            return postdata.weight

if __name__ == '__main__':
        app.run()


 

你可能感兴趣的:(webpy 简单表单一粒)