reload flask on change
from flask import Flask
app = Flask(__name__)
# Define a route for the home page
@app.route('/')
def home():
return 'Hello, World!'
if __name__ == '__main__':
# Run the app with debug mode enabled
app.run(debug=True)
- Import the
Flask
class from theflask
module. - Create an instance of the
Flask
class and assign it to the variableapp
. - Define a route for the home page using the
@app.route
decorator. In this example, the home page is represented by the '/' route. - Define a function named
home
that will be executed when the home page is accessed. This function returns the string 'Hello, World!'. - Check if the script is being run directly (not imported as a module). If so, run the Flask application with debug mode enabled.
- 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.