The Flask Installation and First program execution

Hello programmers, today we are going to learn what is flask how to install it with python and how to run flask programs. So lets start.

Intro to Flask

                Flask is a micro framework for python web development. A framework, in the simple terms. it is a library or collections of libraries whose aim is to solve a part of generic problem instead of specific one. While building any web applications, there are some problems that will needed to be solved for successful execution of program. The Flask is a micro framework because it implements only core functionality but it leaves authentication and database ORMs like more advanced functionlaity.

Ok so here we stop with the theory and start with the coding part step by step.

 

Installation

Installing flask through pip could not be more straightforward. Simply run the following command in your terminal or command prompt.

pip install flask

flask_installation

After installing flask successfully you can import flask into python program just as with any other library.

First Program

So after installing flask successfully open your python in command prompt and write the following code

 

Code:

from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
	return "Hello World!"

if __name__ == "__main__":
	app.run(port=5000,debug=False)

You can get this code file named flask_01.py in download section of this post. After executing the above you will get the hello world  in your browser.

flask_code_output

Note that sometimes it opens your default browser automatically or some times you have to open the running url with provided port number in your browser. (for ex. Here  I have opened the url “127.0.0.1:5000” because I have provided my free port number 5000)

So Here we stop for now. try this by your own. if you face any problem regarding this post feel free to comment below in comment section. To get updated with our new up coming post please subscribe to your newsletter.

Thank you…

Happy Coding…