Bird
0
0

Examine this Flask route code:

medium📝 Debug Q7 of 15
Flask - Ecosystem and Patterns
Examine this Flask route code:
from flask import Flask
app = Flask(__name__)

@app.route('/data')
def data():
    return 'Data'

Why might this code cause an IndentationError?
AThe return statement is not indented inside the function
BThe route decorator is missing parentheses
CFlask app instance is not created properly
DFunction name conflicts with Flask keywords
Step-by-Step Solution
Solution:
  1. Step 1: Check function indentation

    Python requires the function body to be indented. The return statement must be indented inside def data():.
  2. Step 2: Analyze options

    The return statement is not indented inside the function correctly identifies the missing indentation. The route decorator is missing parentheses is incorrect because the decorator syntax is correct. Flask app instance is not created properly is incorrect since the app instance is properly created. Function name conflicts with Flask keywords is invalid as data is not a reserved keyword.
  3. Final Answer:

    The return statement is not indented inside the function -> Option A
  4. Quick Check:

    Python requires indented function bodies [OK]
Quick Trick: Indent function body properly in Flask routes [OK]
Common Mistakes:
MISTAKES
  • Not indenting return or statements inside functions
  • Misusing decorators syntax
  • Naming functions with reserved keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes