0
0
Flaskframework~10 mins

Command pattern with Flask CLI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flask class correctly.

Flask
from flask import [1]
app = [1](__name__)
Drag options to blanks, or click blank then click option'
Aflask
BFlask
CFlaskApp
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'flask' instead of 'Flask'
Using incorrect class names like 'FlaskApp' or 'App'
2fill in blank
medium

Complete the code to define a Flask CLI command using the decorator.

Flask
@app.cli.[1]('hello')
def hello_command():
    print('Hello from CLI!')
Drag options to blanks, or click blank then click option'
Aroute
Bcli
Crun
Dcommand
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@app.cli.cli' instead of '@app.cli.command'
Confusing CLI commands with routes
3fill in blank
hard

Fix the error in the command function to accept a parameter.

Flask
@app.cli.command('greet')
def greet_command(name):
    print(f'Hello, [1]!')
Drag options to blanks, or click blank then click option'
Aname
Bself
Cuser
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name inside the function
Forgetting to use the parameter in the print statement
4fill in blank
hard

Fill both blanks to create a CLI command that takes an argument and prints it.

Flask
@app.cli.command('[1]')
def echo_command(text):
    print(f'You said: [2]')
Drag options to blanks, or click blank then click option'
Aecho
Btext
Cmessage
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching the command name and function name
Using a different variable inside the print statement
5fill in blank
hard

Fill all three blanks to define a CLI command with an option and print the option value.

Flask
import click

@app.cli.command('repeat')
@click.option('--count', default=1, help='Number of repeats')
def repeat_command(count):
    for _ in range([1]):
        print('[2]' * [3])
Drag options to blanks, or click blank then click option'
Acount
BRepeat!
DHello
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name in the loop
Printing the wrong string or not repeating it correctly