python - 单击按钮 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)
解决方案
您可以为此使用 HTML。
<div>
<button onClick="alert('This is a message')">
Click Me
</button>
</div>
推荐阅读
- apache-spark - 如何释放 Dataproc 中块池使用的空间
- amazon-elastic-beanstalk - 在内部谷歌网站上嵌入破折号图
- pandas - 在数据框中创建新的嵌套列
- java - 当他们在 Spring Boot 应用程序中注册他们的详细信息时,我们可以为不同角色(如买家、卖家)发送电子邮件通知吗?
- arrays - 如何以角度从数组中输出项目
- forms - 如何阻止 Flutter“表单”抛出错误?
- android - Unity 2019.3:“Android 手机崩溃”
- database - 我的用户字体端显示搞砸了!但是如果我使用管理员帐户..它工作正常
- mongodb - 嵌套数组中的 $addToSet
- swift - CoreData 和 CloudKit 同步有效,但 NSPersistentStoreRemoteChange 通知永远不会触发