我正在尋找一種方法,當(dāng)我單擊按鈕時,在我的網(wǎng)絡(luò)應(yīng)用程序的同一頁面上顯示通知。這不是表格!只是一個按鈕,當(dāng)我單擊它時,如果單擊按鈕打開,則在屏幕前發(fā)送顯示一條消息,例如“門已打開”,或者如果單擊按鈕警報,則發(fā)送“警報”。我對燒瓶完全是新手!這是我的代碼的一部分:超文本標(biāo)記語言<html> <head> <link rel = "stylesheet" type= "text/css" href= "{{ url_for('static', filename='main.css') }}" > <title> Security </title> </head> <body> <h1>{{message}} </h1> <img class = "displayed" src="{{ url_for('video_feed') }}"> <div id='container'> <input type="submit" value="Alarm" id="submit"> <input type="submit" value="Ouvrir" id="submit2"> </div> </body></html> app.pyimport cv2 from flask import Flask, render_template, Responsefrom flask import request, redirect, flashapp = Flask(__name__)@app.route("/", methods = ["GET", "POST"])def index(): """Video streaming home page.""" return render_template('index.html', message = 'un intru est detecté')def gen(): """Video streaming generator function.""" img = cv2.imread("detection.jpg") img = cv2.resize(img, (0,0), fx=0.5, fy=0.5) frame = cv2.imencode('.jpg', img)[1].tobytes() yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')@app.route('/video_feed')def video_feed(): """Video streaming route. Put this in the src attribute of an img tag.""" return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')if __name__ == '__main__': app.secret_key = 'super secret key' app.run(debug=True)
- 2 回答
- 0 關(guān)注
- 145 瀏覽
添加回答
舉報
0/150
提交
取消