Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask class.
Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Queue or Task instead of Flask.
Using lowercase flask instead of Flask.
✗ Incorrect
The Flask class is imported from the flask module to create the app instance.
2fill in blank
mediumComplete the code to create a new Flask app instance.
Flask
app = [1](__name__) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Queue or Task instead of Flask to create the app.
Forgetting to pass __name__ as argument.
✗ Incorrect
The Flask class is called with __name__ to create the app instance.
3fill in blank
hardFix the error in the code to define a background task function.
Flask
@app.task def [1](): print('Task running')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using names that do not match the decorator or cause confusion.
Using invalid function names.
✗ Incorrect
The function name should be 'run_task' to match typical task naming conventions.
4fill in blank
hardFill both blanks to create a task queue and add a task.
Flask
from celery import [1] app = [2]('tasks')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flask or Queue instead of Celery.
Not matching import and instantiation names.
✗ Incorrect
Celery is imported and instantiated to create the task queue app.
5fill in blank
hardFill all three blanks to define and call a background task.
Flask
@app.task def [1](x, y): return x [2] y result = [3].delay(4, 5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function name and call.
Using wrong operator inside the function.
✗ Incorrect
The function is named 'add', uses '+' to add, and calls add.delay to run asynchronously.