Create an instance of the Flask class, then map URLs to view functions with the @app.route() decorator.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
Flask(__name__) creates the application instance, the object a web server calls for each request. The @app.route('/') decorator binds / to hello_world, and the returned string becomes the response body.
app.run(debug=True) starts the development server when you run the file directly. From the terminal, flask --app hello run --debug does the same, where hello is the module name. Use the development server and its debugger only on your own machine, never in production.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓