DEV Community

Dr. Azad Rasul
Dr. Azad Rasul

Posted on

3- How to reate Hello World App in Flask?

To create Hello World app in Flask, First, import the Flask class from the flask package:

from flask import Flask
Enter fullscreen mode Exit fullscreen mode

Then, set the app as an instance of Flask:

app = Flaks(__name__)
Enter fullscreen mode Exit fullscreen mode

Define a function index route to display “Hello, World! This is my first from Flask”:

@app.route("/")
def hello():
        return 'Hello, World! This is my first app from Flask.'
Enter fullscreen mode Exit fullscreen mode

Save a script as “hello.py

Then run the script with cmd using:

python hello.py
Enter fullscreen mode Exit fullscreen mode

Now open your internet browser and write:

http://192.168.100.2:5000

or localhost:5000

Your first web page should be opened like this:

Image description

To quit running it press CTRL+C

The complete code is:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
        return 'Hello, World! This is my first app from Flask.'

if __name__ == "__main__":
        app.run(debug=True)
Enter fullscreen mode Exit fullscreen mode

* If you like the content, please SUBSCRIBE to my channel for the future content

Top comments (0)