从另一个模块(Flask)重定向

2024-09-28 05:28:14 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个opencv烧瓶相机流代码。生成要流化的帧的函数在app.py之外。我希望能够在事件发生时自动停止流并重定向到page2。我试着在@app.route('/video_feed')中完成,如下代码所示。我花了两天没有结果。在

在应用程序副本在

from flask import Flask, render_template, Response, redirect, url_for, 
import cv2
from applogic import AppLogic

app = Flask(__name__)
vc = cv2.VideoCapture(0)
applogic = AppLogic()


@app.route('/')
def index():
    """Video streaming home page."""
    return render_template('index.html')


@app.route('/page2')
def page2():
    """the page to be redirected to when event happens."""
    return render_template('page2.html')


@app.route('/video_feed')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    temp = applogic.gen()
    if temp != 1
        return Response(applogic.gen(),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
    else: 
        return redirect(url_for('page2'))


if __name__ == '__main__':
    app.run(host='127.0.0.1]', debug=True, threaded=True)

在应用程序.py(请注意压痕):

^{pr2}$

在索引.html公司名称:

<html>
  <head>
    <title>Video Streaming Demonstration</title>
  </head>
  <body>
    <h1>Video Streaming Demonstration</h1>
    <img src="{{ url_for('video_feed') }}">
  </body>
</html>

有一个普通的html“hello world”代码;没有什么特别的

谢谢。在


Tags: 代码importappurlforreturnhtmlvideo

热门问题