Bird
0
0

Identify the error in this Flask polling endpoint code:

medium📝 Debug Q14 of 15
Flask - WebSocket and Real-Time
Identify the error in this Flask polling endpoint code:
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/poll')
def poll():
    data = {'status': 'ok'}
AFunction poll() is missing a return statement
BMissing @app.route decorator
CFlask app is not created properly
DReturning a dict directly without using jsonify causes an error
Step-by-Step Solution
Solution:
  1. Step 1: Check for return statement

    The poll() function defines data but does not return it.
  2. Step 2: Verify function completeness

    Missing return statement means the endpoint returns None by default, causing unexpected empty response.
  3. Final Answer:

    Function poll() is missing a return statement -> Option A
  4. Quick Check:

    Missing return in view function [OK]
Quick Trick: Always include return statement in Flask route handlers [OK]
Common Mistakes:
MISTAKES
  • Missing return statement in route function
  • Forgetting route decorator
  • Not creating Flask app instance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes