Here is Flask's Hello World application which, as we mentioned, contains only a few lines of code. This can be seen in hello.py script, as follows:
# Import required packages:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
After importing the required package, we will create an instance of Flask class, which will be our Web Server Gateway Interface (WSGI) application. The route() decorator is used to indicate what URL should trigger the hello() function, which will print the message Hello World!.
In Flask, you can use the route() decorator to bind a function to a URL.
Execute this script with the following command:
$ python hello.py
You will see this message in your console, telling you that the web server has been started:
* Serving...