Let's think about it this way for a moment
Run Flask (a lightweight Python-based web framework) on a Raspberry Pi and you can display sensor data, an LED control interface, or a home dashboard as a web page — you might recall the 'web server' concept from the Docker tutorial; the difference here is that it's running directly on the Pi, no container needed. Run the Flask app with host='0.0.0.0' and any device on the Pi's local network can reach it via its IP address (not just localhost).
Let's connect it to a real scenario
Install with pip install flask, create a Flask app object in your Python script, define a route (@app.route('/')), and wire an LED control button (an HTML form) into the route logic — then you can visit http://raspberrypi.local:5000 from a phone or computer browser and remotely control the LED. This is the basic pattern behind any IoT dashboard.
Let's look at it together
from flask import Flask
from gpiozero import LED
app = Flask(__name__)
led = LED(17)
@app.route('/')
def home():
return '<h1>Pi LED Control</h1><a href="/on">Turn On</a> | <a href="/off">Turn Off</a>'
@app.route('/on')
def turn_on():
led.on()
return 'LED is ON'
@app.route('/off')
def turn_off():
led.off()
return 'LED is OFF'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)Visiting http://raspberrypi.local:5000 from a browser (phone/computer) should show the LED control page, and clicking the link should immediately switch the physical LED on/off.5-minute try-it
Write your own Flask app and run it on the Pi (if you have one) — visit it from a phone browser and try remotely controlling the LED.
A quick word of caution
Only use Flask's debug=True mode for development — leaving debug mode on for a production/always-on Pi project is a security risk (the security misconfiguration concept from the Cybersecurity tutorial).