How to Serve MP4 Video with Flask

Viewed 997

I want flask to play videos from local resources of my PC on Windows 10.

app.py

app = Flask(__name__)

@app.route("/", methods=['GET'])
def main():

    return render_template('index.html')

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80, threaded=True)

index.html

In index.html a js script to use the modified player

<!DOCTYPE html>
<html>
<body>

    <script src="{{ url_for('static', filename='player.js') }}" type="text/javascript"></script>

    <div id="player"></div>

      <script>
      var player = new Playerjs({id:"player", file:"F://Downloads//test.mp4"});
      </script>

</body>
</html>

If I put the video file in the static folder everything is fine.

But i need flask to play videos from local resources.

With something like this: F://Downloads//test.mp4

Server errors:

Not allowed to load local resource: file:///F://Downloads//test.mp4

1 Answers

try this var player = new Playerjs({id:"player", file:"F:/Downloads/test.mp4"});

Related