Bird
0
0

Which of the following is the correct way to define a custom Flask CLI command using the command pattern?

easy📝 Syntax Q3 of 15
Flask - Ecosystem and Patterns
Which of the following is the correct way to define a custom Flask CLI command using the command pattern?
A@cli.command()\ndef hello():\n print('Hello!')
B@app.command()\ndef hello():\n print('Hello!')
C@app.cli.command()\ndef hello():\n print('Hello!')
D@app.route('/hello')\ndef hello():\n print('Hello!')
Step-by-Step Solution
Solution:
  1. Step 1: Recognize the correct decorator

    Custom Flask CLI commands use the @app.cli.command() decorator.
  2. Step 2: Identify incorrect decorators

    @app.command() and @cli.command() are invalid, and @app.route() is for HTTP routes, not CLI commands.
  3. Final Answer:

    @app.cli.command()\ndef hello():\n print('Hello!') -> Option C
  4. Quick Check:

    Decorator for CLI command = @app.cli.command() [OK]
Quick Trick: Use @app.cli.command() to define CLI commands [OK]
Common Mistakes:
MISTAKES
  • Using @app.command() instead
  • Confusing CLI commands with routes
  • Using @cli.command() without app context

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes