Bird
0
0

Given this Flask polling endpoint code, what will the client receive when requesting '/poll'?

medium📝 component behavior Q13 of 15
Flask - WebSocket and Real-Time
Given this Flask polling endpoint code, what will the client receive when requesting '/poll'?
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/poll')
def poll():
    data = {'message': 'Hello', 'count': 5}
    return jsonify(data)
AHello 5
B{"message": "Hello", "count": 5}
C{message: Hello, count: 5}
DError: jsonify not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand jsonify output

    jsonify converts Python dict to JSON string with double quotes and correct syntax.
  2. Step 2: Check returned data format

    The returned JSON string will be {"message": "Hello", "count": 5} as a JSON response.
  3. Final Answer:

    {"message": "Hello", "count": 5} -> Option B
  4. Quick Check:

    jsonify returns JSON string = {"message": "Hello", "count": 5} [OK]
Quick Trick: jsonify returns JSON string with double quotes [OK]
Common Mistakes:
MISTAKES
  • Expecting plain text instead of JSON
  • Confusing Python dict syntax with JSON
  • Assuming jsonify is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes