Flask is a small and simple web framework for Python that lets you create web servers easily on a Raspberry Pi to handle web requests and show web pages.
Click to reveal answer
beginner
How do you install Flask on a Raspberry Pi?
You open the terminal and run: pip install flask. This command downloads and installs Flask so you can use it in your Python programs.
Click to reveal answer
beginner
What is the purpose of the @app.route('/') decorator in a Flask app?
It tells Flask which web address (URL) should run the function below it. For example, @app.route('/') means the function runs when someone visits the home page.
Click to reveal answer
intermediate
Why do you use app.run(host='0.0.0.0') on a Raspberry Pi?
Using host='0.0.0.0' makes the Flask server listen on all network addresses, so other devices on the same network can access the web server running on the Raspberry Pi.
Click to reveal answer
beginner
What is a simple Flask app example to show 'Hello, Raspberry Pi!' on the home page?
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, Raspberry Pi!'
if __name__ == '__main__':
app.run(host='0.0.0.0')
This code creates a web server that shows the message when you visit the Pi's IP address.
Click to reveal answer
What command installs Flask on a Raspberry Pi?
Aapt-get install flask
Bpython flask install
Cnpm install flask
Dpip install flask
✗ Incorrect
Flask is a Python package installed using pip, so the correct command is pip install flask.
What does @app.route('/') do in a Flask app?
ADefines the home page URL route
BStarts the Flask server
CImports Flask module
DStops the Flask server
✗ Incorrect
The @app.route('/') decorator tells Flask which URL path runs the function below it, here the home page.
Why use host='0.0.0.0' in app.run() on Raspberry Pi?
ATo install Flask
BTo allow access from other devices on the network
CTo disable the server
DTo run the server only on localhost
✗ Incorrect
Setting host='0.0.0.0' makes the server listen on all network interfaces, so other devices can connect.
Which language is Flask written in?
APython
BJavaScript
CJava
DC++
✗ Incorrect
Flask is a web framework written in Python.
What do you need to do before running a Flask app on Raspberry Pi?
AFormat the SD card
BInstall Node.js
CInstall Flask using pip
DInstall Java
✗ Incorrect
You must install Flask with pip before running Flask apps.
Explain how to create and run a simple Flask web server on a Raspberry Pi.
Think about installation, coding, running, and accessing the server.
You got /5 concepts.
Describe why setting the host to '0.0.0.0' is important when running Flask on Raspberry Pi.
Consider how devices on the same network reach the server.
You got /4 concepts.
Practice
(1/5)
1. What does the @app.route decorator do in a Flask web server on Raspberry Pi?
easy
A. It installs Flask on the Raspberry Pi.
B. It starts the Flask server to listen for requests.
C. It defines the URL path that triggers a specific function.
D. It stops the Flask server from running.
Solution
Step 1: Understand the role of @app.route
This decorator tells Flask which URL path should run the function below it.
Step 2: Connect URL to function
When a user visits that URL, Flask runs the linked function to generate a response.
Final Answer:
It defines the URL path that triggers a specific function. -> Option C
Quick Check:
@app.route sets URL path [OK]
Hint: Remember: route = URL path to function [OK]
Common Mistakes:
Thinking it starts or stops the server
Confusing it with installing Flask
Assuming it runs the server automatically
2. Which of the following is the correct way to run a Flask app on Raspberry Pi so it is accessible from other devices on the network?
easy
A. app.run(host='0.0.0.0')
B. app.run(host='127.0.0.1')
C. app.run()
D. app.run(port=8080)
Solution
Step 1: Understand host parameter in app.run()
By default, Flask listens only on localhost (127.0.0.1), meaning only the Pi itself can access it.
Step 2: Use host='0.0.0.0' to allow network access
Setting host to '0.0.0.0' tells Flask to listen on all network interfaces, so other devices can connect.
Final Answer:
app.run(host='0.0.0.0') -> Option A
Quick Check:
host='0.0.0.0' allows network access [OK]
Hint: Use host='0.0.0.0' to share server on network [OK]
Common Mistakes:
Using default host which blocks external access
Confusing port with host
Using localhost IP which restricts access
3. What will be the output when you visit http://raspberrypi.local/hello given this Flask code on Raspberry Pi?
from flask import Flask
app = Flask(__name__)
@app.route('/hello')
def hello():
return 'Hello, Raspberry Pi!'
if __name__ == '__main__':
app.run(host='0.0.0.0')
medium
A. Server does not start
B. 404 Not Found error
C. SyntaxError
D. Hello, Raspberry Pi!
Solution
Step 1: Check the route and function
The route '/hello' is defined and returns the string 'Hello, Raspberry Pi!'.
Step 2: Accessing the URL
Visiting /hello triggers the function and returns the string as the web page content.
Final Answer:
Hello, Raspberry Pi! -> Option D
Quick Check:
Route '/hello' returns greeting string [OK]
Hint: Match URL path to function return value [OK]
Common Mistakes:
Expecting a 404 error if route is correct
Thinking code has syntax errors
Assuming server won't start with host='0.0.0.0'
4. Identify the error in this Flask code snippet intended to run on Raspberry Pi:
from flask import Flask
app = Flask(__name__)
@app.route('/status')
def status():
print('Server is running')
if __name__ == '__main__':
app.run(host='0.0.0.0')
medium
A. Incorrect host value in app.run().
B. Missing indentation for the print statement inside the function.
C. Missing import statement for Flask.
D. Route decorator syntax is wrong.
Solution
Step 1: Check function body indentation
The print statement inside the function must be indented to be part of the function block.
Step 2: Verify other parts
Host value '0.0.0.0' is correct, Flask is imported, and route syntax is valid.
Final Answer:
Missing indentation for the print statement inside the function. -> Option B
Quick Check:
Python requires indentation inside functions [OK]
Hint: Indent function code properly in Python [OK]
Common Mistakes:
Ignoring indentation errors
Changing host unnecessarily
Misreading route decorator syntax
5. You want your Flask app on Raspberry Pi to show different messages at / and /info. Which code correctly sets up these two routes?
hard
A. from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Welcome!'
@app.route('/info')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0')
B. from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Welcome!'
@app.route('/')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0')
C. from flask import Flask
app = Flask(__name__)
@app.route('/info')
def home():
return 'Welcome!'
@app.route('/')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0')
D. from flask import Flask
app = Flask(__name__)
@app.route('/home')
def home():
return 'Welcome!'
@app.route('/info')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0')
Solution
Step 1: Check route paths and functions
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Welcome!'
@app.route('/info')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0') correctly uses '/' for home and '/info' for info, each with its own function returning the right message.
Step 2: Verify no route conflicts
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Welcome!'
@app.route('/')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0') uses '/' twice, which causes conflict. from flask import Flask
app = Flask(__name__)
@app.route('/info')
def home():
return 'Welcome!'
@app.route('/')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0') swaps routes and functions incorrectly. from flask import Flask
app = Flask(__name__)
@app.route('/home')
def home():
return 'Welcome!'
@app.route('/info')
def info():
return 'Raspberry Pi Info'
app.run(host='0.0.0.0') uses '/home' instead of '/'.
Final Answer:
Option A correctly defines two distinct routes '/' and '/info'. -> Option A
Quick Check:
Unique routes need unique paths [OK]
Hint: Use unique URLs for each route function [OK]
Common Mistakes:
Defining two functions for the same route
Swapping route paths and function names
Using wrong URL paths like '/home' instead of '/'
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.