V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
GPU
V2EX  ›  Python

web.py 按钮问题,不知道怎么解决

  •  
  •   GPU · 2015-07-14 10:30:33 +08:00 · 1546 次点击
    这是一个创建于 3225 天前的主题,其中的信息可能已经有所发展或是发生改变。

    弄了一个网页 ,目的是网页上面点击按钮,main.py接收到POST

    然后执行另一个方法(类)发送串口指令到蓝牙模块然后另一边的蓝牙模块接收后,单片机处理

    改来改去不知道怎么写 ,麻烦各位指教一下 ,下面是代码,代码有点乱,新手上路谢谢啦

    web.py 的 cookbook 我是看过的,不过看得不是很懂就了

    对于 web.form.Form.Button 还是 web.form.Button 还是不清楚怎么用

    main.py

    #!/usr/bin/env python
    
    import web
    from web import form
    
    USERNAME = "GPU"
    PASSWORD = "GPU"
    render = web.template.render('templates/')
    
    url = (
            '/', 'index'
    )
    app = web.application(url, globals())
    
    myform = form.Form(
        form.Textbox("username"),
        form.Password("password", form.notnull),
        form.Button("submit", type="submit", description="Auth")
    )
    myBotton = form.Form(
        form.Botton("action", value="Open", html="Open"),
        form.Botton("Reset")
    )
    
    def verifyuser(uname, passwd):
        if uname == USERNAME and passwd == PASSWORD:
            return 1
        else:
            return 0
    
    class index:
        def GET(self):
            # form = myform()
            Botton = myBotton()
            return render.index(Botton)
    
        def POST(self):
            # form = myform()
    
            # if not form.validates():
            #   return render.auth(form)
            # else:
                # if(verifyuser(form['username'].value, form['password'].value)):
                # i = web.form(name="")
                if form.get_value == "Open":
                    return "Door opened!"
                # if form.name == "Rest":
                #   return "reset"
    
    if __name__ == "__main__":
        web.internalerror = web.debugerror
        app.run()
    

    index.html

    <body>
        <div class="container">
          <div class="header">
            <h3>Test</h3>
          </div>
          <form action="/" method="POST" class="jumbotron">
          $def with 
            <input type="submit" class="btn btn-success" name="OpenDoor"></input>
            <input type="submit" class="btn btn-success" name="Reset"></input>
        </form>
    
      </body>
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3070 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:06 · PVG 23:06 · LAX 08:06 · JFK 11:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.