小编Adi*_*lik的帖子

Flask Button运行Python而不刷新页面?

我刚刚开始使用python和flask(对于raspberry pi).我想要一个Web应用程序,它将执行一些python代码来平移和倾斜摄像机并显示视频流.

我现在对于烧瓶的代码是:

from flask import Flask, render_template
import time
import serial
#ser = serial.Serial('/dev/ttyUSB0',9600)
app = Flask(__name__)
@app.route('/')
@app.route('/<cmd>') #each button in my html redirects to a specified directory
def execute(cmd=None):
if cmd == "down":
    print "Moving Down"
    #ser.write("D")

if cmd == "up":
    print "Moving Up"
    #ser.write("U")

if cmd == "left":
    print "Moving Left"
   # ser.write("L")

if cmd == "right":
    print "Moving Right"
    #ser.write("R")

if cmd == "reset":
    print "Reseting.."
    #ser.write("X")
return render_template("main.html")


if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, …
Run Code Online (Sandbox Code Playgroud)

python flask raspberry-pi

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

flask ×1

python ×1

raspberry-pi ×1