Bird
0
0

You wrote this Flask code but get an error when running it:

medium📝 Debug Q14 of 15
Flask - Ecosystem and Patterns
You wrote this Flask code but get an error when running it:
from flask import Flask
app = Flask(__name__)

@app.route('/hello')
def hello():
print('Hello World!')
What is the main issue causing the error?
AIndentation error inside the function
BMissing parentheses in print statement
CRoute decorator syntax is wrong
DFlask app not initialized properly
Step-by-Step Solution
Solution:
  1. Step 1: Check function body indentation

    Python requires the function body to be indented; here, print is not indented.
  2. Step 2: Confirm other syntax correctness

    Print statement has parentheses (Python 3), route decorator syntax and app initialization are correct.
  3. Final Answer:

    Indentation error inside the function -> Option A
  4. Quick Check:

    Python needs indented function bodies [OK]
Quick Trick: Check indentation inside functions for errors [OK]
Common Mistakes:
MISTAKES
  • Assuming print needs fixing in Python 3
  • Blaming route decorator syntax
  • Thinking Flask app init is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes