Bird
0
0

Identify the error in this Flask CLI command code:

medium📝 Debug Q6 of 15
Flask - Ecosystem and Patterns
Identify the error in this Flask CLI command code:
from flask import Flask
app = Flask(__name__)

@app.cli.command()
def greet(name):
    print(f'Hello, {name}!')
Aprint statement syntax is invalid
BMissing click.argument or click.option decorator for 'name'
CFunction name cannot be 'greet'
DFlask app instance is not created correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check function parameters

    The function expects a parameter name but no click.argument or click.option decorates it to provide a value.
  2. Step 2: Identify missing decorator

    Without a decorator, Flask CLI cannot pass a value to name, causing an error.
  3. Final Answer:

    Missing click.argument or click.option decorator for 'name' -> Option B
  4. Quick Check:

    Parameters need decorators to receive CLI input [OK]
Quick Trick: Decorate parameters to accept CLI inputs [OK]
Common Mistakes:
MISTAKES
  • Forgetting click.option or click.argument
  • Assuming parameters auto-bind
  • Misnaming function parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes