Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'flask' instead of 'Flask'
Using incorrect class names like 'FlaskApp' or 'App'
✗ Incorrect
The Flask class is imported from the flask package using from flask import Flask.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@app.cli.cli' instead of '@app.cli.command'
Confusing CLI commands with routes
✗ Incorrect
The @app.cli.command decorator defines a CLI command in Flask.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name inside the function
Forgetting to use the parameter in the print statement
✗ Incorrect
The function parameter is named 'name', so use it inside the print statement.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching the command name and function name
Using a different variable inside the print statement
✗ Incorrect
The command name is 'echo' and the variable used inside the print is 'text'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name in the loop
Printing the wrong string or not repeating it correctly
✗ Incorrect
The loop runs 'count' times, printing 'Repeat!' repeated 'count' times each loop.