pure & tornado -- form

在工做中经常使用的几个formcss

  • aligned-form & selecthtml

handler代码    handlers/form.py
python

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # 表单模板测试
        self.render("form.html")
        
    def post(self):
        print self.request.arguments
        print self.get_argument("cb", "xx")

template模板    templates/form.htmlios

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>测试 pure form</title>
        <link rel="stylesheet" href="/static/css/pure/forms.css" />
    </head>
    <body>
        <form class="pure-form pure-form-aligned" method="post">
            <fieldset>
                <div class="pure-control-group">
                    <label for="name">Username</label>
                    <input id="name" name="name" type="text" placeholder="Username">
                </div>
        
                <div class="pure-control-group">
                    <label for="password">Password</label>
                    <input id="password" name="password" type="password" placeholder="Password">
                </div>
        
                <div class="pure-control-group">
                    <label for="email">Email Address</label>
                    <input id="email" name="email" type="email" placeholder="Email Address">
                </div>
        
                <div class="pure-control-group">
                    <label for="foo">Extra Label</label>
                    <input id="foo" name="foo" type="text" placeholder="Enter something here...">
                </div>
                
                <div class="pure-control-group">
                    <label for="state">State</label>
                    <select id="state" name="state">
                        <option>AL</option>
                        <option>CA</option>
                        <option>IL</option>
                    </select>
                </div>
                
                <div class="pure-controls">
                    <label for="cb" class="pure-checkbox">
                        <input id="cb" name="cb" type="checkbox"> I've read the terms and conditions
                    </label>
        
                    <button type="submit" class="pure-button pure-button-primary">Submit</button>
                </div>
            </fieldset>
        </form>
    </body>
</html>

        注: 必须有name字段, tornado经过name识别参数的
web

        效果图tornado

        

  • checkbox & radiopost

handler代码    handlers/form2.py测试

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # 表单模板测试
        self.render("form.html")
        
    def post(self):
        print self.request.arguments
        print self.get_argument("cb", "xx")

template模板    templates/form2.htmlthis

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>测试 pure form</title>
        <link rel="stylesheet" href="/static/css/pure/forms.css" />
    </head>
    <body>
        <form class="pure-form" method="post">
            <label for="option-one" class="pure-checkbox">
                <input id="option-one" name="cb" type="checkbox" value="cb1">
                Here's option one.
            </label>
        
            <label for="option-two" class="pure-radio">
                <input id="option-two" type="radio" name="optionsRadios" value="rd1" checked>
                Here's a radio button. You can choose this one..
            </label>
            <label for="option-three" class="pure-radio">
                <input id="option-three" type="radio" name="optionsRadios" value="rd2">
                ..Or this one!
            </label>

            <button type="submit" class="pure-button pure-button-primary">Submit</button>
        </form>
    </body>
</html>

        注: radio box若是要互斥,name必须一致
spa

        效果图    

        

相关文章
相关标签/搜索