为了账号安全,请及时绑定邮箱和手机立即绑定

单击按钮 FLASK 时显示通知

单击按钮 FLASK 时显示通知

繁星点点滴滴 2023-10-10 16:49:34
我正在寻找一种方法,当我单击按钮时,在我的网络应用程序的同一页面上显示通知。这不是表格!只是一个按钮,当我单击它时,如果单击按钮打开,则在屏幕前发送显示一条消息,例如“门已打开”,或者如果单击按钮警报,则发送“警报”。我对烧瓶完全是新手!这是我的代码的一部分:超文本标记语言<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 回答

?
PIPIONE

TA贡献1829条经验 获得超9个赞

为此,您可以使用 HTML。


<div>

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


   Click Me


   </button>

</div>


查看完整回答
反对 回复 2023-10-10
?
千巷猫影

TA贡献1829条经验 获得超7个赞

根据我对您的要求的理解,您只需要在单击按钮时显示消息即可。为此,flask 中无需执行任何操作。

按钮添加点击事件,添加显示消息。要显示消息,1.简单的事情就是使用alert()。2. 如果您需要色彩缤纷的东西,请使用 bootstrap modal 。


查看完整回答
反对 回复 2023-10-10
  • 2 回答
  • 0 关注
  • 58 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信