Bird
0
0

What will happen if you run this Flask app on Raspberry Pi?

medium📝 Predict Output Q5 of 15
Raspberry Pi - Web Server and API
What will happen if you run this Flask app on Raspberry Pi?
from flask import Flask
app = Flask(__name__)

@app.route('/data')
def data():
    return {'temperature': 25, 'humidity': 60}

if __name__ == '__main__':
    app.run()

And then visit http://localhost:5000/data?
AA 404 Not Found error
BA TypeError because dict cannot be returned
CA plain text string of the dict
DA JSON response with temperature and humidity
Step-by-Step Solution
Solution:
  1. Step 1: Understand Flask automatic JSON conversion

    Flask automatically converts Python dicts returned from view functions into JSON responses.
  2. Step 2: Check route and return value

    The '/data' route returns a dict with temperature and humidity, so visiting it returns JSON with those values.
  3. Final Answer:

    A JSON response with temperature and humidity -> Option D
  4. Quick Check:

    Returning dict = JSON response [OK]
Quick Trick: Return dict in Flask to send JSON response automatically [OK]
Common Mistakes:
MISTAKES
  • Thinking dict return causes error
  • Expecting plain text instead of JSON
  • Assuming route does not exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes