Create hello world app with flask

create-hello-world-app-with-python-flask

Hello World, Today we are going to create hello world app with flask. Flask is micro framework which is built with python. In this simple tutorial we will discuss about the following things.

  • Introduction of flask
  • Install Flask on your local system
  • Create hello world app with flask


Introduction of Flask

According to their official website:

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.

You can read the full documentation and tutorials of flask on their official website.


Install Flask on your local system

Installation of flask is very easy. Before installing flask, make sure that you have installed following tools on your system. If you have not installed python on your machine then you can following this link and install the python.

We need one more thing to install flask and that is pip. Pip is python package manager. When you install latest version of python then it will add by default. But if you need to install manually then you can install it from this link.

Verify that python and pip is installed on your system with following step:

  • Open Command Prompt.
  • For python installation run this command python –version
  • For pip installation run this command pip –version
  • You will see the version number of both tools.

Now we have settled up our environment for creating flask app.


Create hello world app with flask

In this step we will create our first hello world app with flask.

  • Create hello_world folder and go this folder via command prompt or terminal.
  • Create hello_world.py file in this folder with following code.
from flask import Flask
app=Flask(__name__)
@app.route('/')
def hello_world():
	return "Hello World"

if __name__=='__main__':
	app.run(debug=True)
  • Now run this file with command python hello_world.py. Make sure that you are in Hello World Folder.
  • When you have ran the above command you will see the following screen in command prompt.

run-file

 

  • Now open you browser with given url and you will see the Hello World Message on your screen.

Congratulations, you have created you first app with flask.

Leave a Reply