0
0
Flaskframework~10 mins

What is Flask - Visual Explanation

Choose your learning style9 modes available
Concept Flow - What is Flask
Start Flask App
Define Routes
Receive HTTP Request
Match Route
Run View Function
Return Response
Send Response to Browser
This flow shows how Flask starts, listens for requests, matches routes, runs code, and sends back responses.
Execution Sample
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello, Flask!'
This code creates a simple Flask app that shows 'Hello, Flask!' when you visit the home page.
Execution Table
StepActionDetailsResult
1Create Flask appapp = Flask(__name__)App instance ready to handle requests
2Define route '/'@app.route('/')Route '/' linked to home() function
3Receive HTTP GET requestBrowser visits '/' URLRequest received by Flask
4Match routeRequest URL '/' matches route '/'home() function selected
5Run view functionExecute home()Returns string 'Hello, Flask!'
6Send responseSend 'Hello, Flask!' back to browserBrowser displays 'Hello, Flask!'
7EndNo more actionsRequest cycle complete
💡 Request handled and response sent, Flask waits for next request
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 5Final
appNoneFlask instanceFlask instance with route '/'Flask instance with route '/'Flask instance with route '/'
requestNoneNoneNoneHTTP GET '/' processedNone
responseNoneNoneNone'Hello, Flask!''Hello, Flask!' sent
Key Moments - 2 Insights
Why do we use @app.route('/') before the function?
The @app.route('/') tells Flask which URL should run the function. See execution_table step 2 where the route is linked to the function.
What happens when the browser visits the URL '/'?
Flask receives the request, matches it to the route '/', runs the linked function, and sends back the response. See steps 3 to 6 in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result after step 4?
AResponse is sent to browser
Bhome() function is selected to run
CFlask app is created
DRoute '/' is defined
💡 Hint
Check the 'Result' column in row for step 4 in execution_table
At which step does Flask send the response back to the browser?
AStep 3
BStep 5
CStep 6
DStep 2
💡 Hint
Look for the step where 'Send response' action happens in execution_table
If we add another route, how would variable 'app' change after step 2?
AIt would have multiple routes linked
BIt would lose the first route
CIt would become None
DIt would not change
💡 Hint
See variable_tracker for 'app' after step 2 and think about adding routes
Concept Snapshot
Flask is a small web framework in Python.
You create an app with Flask(__name__).
Use @app.route('path') to link URLs to functions.
Functions return responses sent to browsers.
Flask listens for requests and runs matching functions.
Simple and flexible for web apps.
Full Transcript
Flask is a lightweight web framework for Python. You start by creating a Flask app instance. Then you define routes using the @app.route decorator to connect URLs to Python functions. When a browser sends a request to a URL, Flask matches it to a route, runs the linked function, and sends back the function's return value as the response. This process repeats for each request, allowing you to build web applications easily.