新建 工程
./test/test.py
#coding:utf-8
from flask import Flask, render_template,request
app= Flask(__name__)
@app.route('/',methods=['GET', 'POST'])
def test():
if request.method == 'POST': #当按钮被按下时接收参数
all = request.form #接收所有参数
i = request.form["ID"] #接收键值为ID的参数
n = request.form["NAME"] #接收键值为NAME的参数
v = request.form["VALUE"] #接收键值为VALUE的参数
print all
print i
print n
print v
return render_template('test.html')
if __name__=='__main__':
app.run()
./test/templates/test.html
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(function(){
$("button").click(function(){
$.post("/",{ID:this.id,NAME:this.name,VALUE:this.value},function(data,status){});
});
});
</script>
<button id="python" name="RaspBerry PI" value="RUN" style="height:30px;width:150px;">传参</button>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>