[英]Deploying Flask application on heroku
I'm trying to deploy my flask application on heroku.我正在尝试在 heroku 上部署我的 flask 应用程序。 However it doesn't seem to work out.
然而,它似乎并不奏效。 I don't know if it has to do with port or something else.
我不知道它是否与端口或其他什么有关。 The code however works on localhost.
然而,该代码适用于本地主机。 I'd like to know if I need to make some modifications in this code.
我想知道是否需要对此代码进行一些修改。
Flask code: Flask 代码:
from flask import Flask, render_template, Response
import cv2
app = Flask(__name__)
camera = cv2.VideoCapture(0)
def gen_frames():
while True:
success, frame = camera.read()
if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.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():
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True, port=5000)
html code: html 代码:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Live Streaming Demonstration</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2">
<h3 class="mt-5">Live Streaming</h3>
<img src="{{ url_for('video_feed') }}" width="100%">
</div>
</div>
</div>
</body>
</html>
I'm new to both Flask and Heroku, and I'm stuck here.我是 Flask 和 Heroku 的新手,我被困在这里。 Any help would be really appreciated.
任何帮助将非常感激。
From what I understand Heroku sets its own ports for each app so you could try somthing like this:据我了解,Heroku 为每个应用程序设置了自己的端口,因此您可以尝试这样的事情:
app.run(debug=True, port=process.env.PORT)
If not please let me know如果没有请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.