Bird
0
0

Identify the error in this Flask CLI command code:

medium📝 Debug Q14 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 hello():
    print('Hello from CLI')

if __name__ == '__main__':
    app.run()
AMissing @click.argument decorator
BUsing print instead of click.echo
CRunning app.run() in CLI command file
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Review the purpose of app.run()

    app.run() starts the Flask web server and is not needed or appropriate in CLI command files.
  2. Step 2: Understand CLI command usage

    Flask CLI commands run via flask command, so running app.run() here will start the server unnecessarily and block CLI commands.
  3. Final Answer:

    Running app.run() in CLI command file -> Option C
  4. Quick Check:

    app.run() should not be in CLI command files [OK]
Quick Trick: Don't call app.run() in CLI command scripts [OK]
Common Mistakes:
MISTAKES
  • Thinking print is wrong (it's allowed but click.echo preferred)
  • Assuming @click.argument is always required
  • Not separating web server run from CLI commands

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes