To create Hello World app in Flask, First, import the Flask class from the flask package:
from flask import Flask
Then, set the app as an instance of Flask:
app = Flaks(__name__)
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.'
Save a script as “hello.py”
Then run the script with cmd using:
python hello.py
Now open your internet browser and write:
Your first web page should be opened like this:
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)
* If you like the content, please SUBSCRIBE to my channel for the future content
Top comments (0)