reload flask on change

from flask import Flask

app = Flask(__name__)

# Define a route for the home page
def home():
    return 'Hello, World!'

if __name__ == '__main__':
    # Run the app with debug mode enabled
  1. Import the Flask class from the flask module.
  2. Create an instance of the Flask class and assign it to the variable app.
  3. Define a route for the home page using the @app.route decorator. In this example, the home page is represented by the '/' route.
  4. Define a function named home that will be executed when the home page is accessed. This function returns the string 'Hello, World!'.
  5. Check if the script is being run directly (not imported as a module). If so, run the Flask application with debug mode enabled.
  6. Debug mode allows automatic reloading of the server when changes are detected.

Note: Ensure that you have Flask installed in your environment (pip install Flask) before running this code.