我正在尝试使用烧瓶上传视频并在 html 页面中播放,但问题是它没有播放。我使用了下面的代码:
UPLOAD_FOLDER = 'static/'
@app.route('/')
def upload_form():
return render_template('upload.html')
@app.route('/', methods=['POST'])
def upload_video():
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No image selected for uploading')
return redirect(request.url)
else:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# print('upload_video filename: ' + filename)
flash('Video successfully uploaded and displayed below')
return render_template('upload.html', filename=filename)
@app.route('/display/<filename>')
def display_video(filename):
# print('display_video filename: ' + filename)
return redirect(url_for('static', filename=filename), code=301)
if __name__ == '__main__':
app.run(threaded=True)
在 html 文件中:
<p>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
</p>
{% if filename %}
<div style="margin: 10px auto;">
<video autoplay="autoplay" controls="controls" preload="preload">
<source src={{ url_for('display_video', filename=filename) }} type="video/mp4"></source>
</video>
</div>
{% endif %}
<form method="post" action="/" enctype="multipart/form-data">
<dl>
<p>
<input type="file" name="file" autocomplete="off" required>
</p>
</dl>
<p>
<input type="submit" value="Upload">
</p>
</form>
视频已上传但无法播放,我无法播放播放按钮或与之互动