首页 > 解决方案 > 单击按钮 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> 

应用程序.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)

标签: pythonhtmlcss

解决方案


您可以为此使用 HTML。

<div>
  <button onClick="alert('This is a message')">

   Click Me

   </button>
</div>

推荐阅读