Bird
0
0

What happens if a Flask polling endpoint returns a Python dictionary directly without using jsonify? ```python @app.route('/poll') def poll(): return {'message': 'hello'} ```

medium📝 Predict Output Q5 of 15
Flask - WebSocket and Real-Time
What happens if a Flask polling endpoint returns a Python dictionary directly without using jsonify? ```python @app.route('/poll') def poll(): return {'message': 'hello'} ```
AFlask returns plain text with dictionary string
BFlask raises a TypeError
CFlask automatically converts it to JSON response
DFlask returns a 500 Internal Server Error
Step-by-Step Solution
Solution:
  1. Step 1: Recall Flask 2.x automatic JSON conversion

    Modern Flask versions automatically convert dict return values to JSON responses.
  2. Step 2: Confirm behavior for direct dict returns

    Returning a dict is equivalent to returning jsonify(dict) in Flask 2.x and later.
  3. Final Answer:

    Flask automatically converts it to JSON response -> Option C
  4. Quick Check:

    Flask auto-converts dict to JSON [OK]
Quick Trick: Flask 2.x+ auto-converts dict returns to JSON [OK]
Common Mistakes:
MISTAKES
  • Expecting TypeError for dict return
  • Thinking plain text is returned
  • Assuming server error without jsonify

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes