How to Stream Video using Flask

2020-04-06 Uttkarsh Kabde

Hello programmers, today we are going to took one step ahead in our flask tutorial. Before starting coding this make sure you have basic knowledge of what is flask?,where it is used? and installing flask into your system. To know about this take a look at Here. So today we are going to create a simple webpage using flask and will try to view youtube video into this. So lets start.

To do so we need the library

flask (pip install flask)

run the command and the flask library and its components will get installed into your system. After this short installation process lets start actual coding.

 

Code:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def homepage():
    return """
    <h1>Hello world!</h1>

    <iframe src="https://www.youtube.com/embed/RK1K2bCg4J8?autoplay=1" width="853" height="480" ></iframe>
    """

if __name__ == '__main__':
    app.run(debug=True, use_reloader=True)

 

Here

 <h1>Hello world!</h1> is the heading1 tag usually used in html language. Here we are going to use this just as test case to make sure our page is loading correctly.

<iframe src="https://www.youtube.com/embed/RK1K2bCg4J8?autoplay=1" width="853" height="480" ></iframe> This is iframe tag is An inline frame that is  used to embed another document within the current HTML document. Here we are going to embed youtube sample video into our webpage. Here we are creating a window of  width=”853” and height=”480” in which our sample video will be played.

Note that when you are using any different video from youtube just change watch?v to embed followed by video id.(Here video id is RK1K2bCg4J8)

Aslo we are using use_reloader=True here which will help us to reload and fork the process if modules or code  were changed.

After running above code the result will be same as seen below.

output_flask_webpage

Here we stop for now. will be back soon with new contents. if you face any problem regarding this post, feel free to comment below. we will make sure to resolve your problem regarding this.

Thank you…

Happy coding…


About author

Card image cap
Uttkarsh Kabde

Currently I am Persuing Mtech in IT at Shri Guru Gobind Singh Institute of Engineering and Technology, Nanded!

-Web App Developer

0 Comments


Scroll to Top