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

2015-07-14 10:30:33 +08:00
 GPU

弄了一个网页 ,目的是网页上面点击按钮,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>
1552 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/205536

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX