弄了一个网页 ,目的是网页上面点击按钮,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>