Category: python
creating your first flask application
Published on 30 Sep 2026
Explanation
Import Flask and create an application instance using the Flask class.
Code:
from flask import Flask app = Flask(__name__)
Explanation
Create a route using the @app.route decorator and return a response.
Code:
@app.route('/')
def home():
return 'Hello Flask!'
Explanation
Run the application using Flask's development server.
Code:
if __name__ == '__main__':
app.run(debug=True)
Explanation
The browser sends a request to the root URL and Flask executes the function mapped to that route.
Code:
GET / | v home() | v 'Hello Flask!'
Explanation
Debug mode automatically reloads the development server when code changes and provides debugging information during development.
Code:
app.run(
debug=True,
host='127.0.0.1',
port=5000
)