Я ищу способ отображать уведомление на той же странице моего веб-приложения, когда нажимаю на кнопку.
Это не форма !!! Просто кнопка, и когда я нажимаю на нее, перед моим экраном появляется сообщение типа «дверь открыта», если нажать на кнопку «открыть», или «ТРЕВОГА», если нажата кнопка тревоги.
Я ПОЛНОСТЬЮ NOVICE ON FLASK!
ЗДЕСЬ является частью моего кода:
HTML
<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.py
import cv2
from flask import Flask, render_template, Response
from flask import request, redirect, flash
app = 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)