0
0
Djangoframework~10 mins

Defining tasks in Django - 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 task decorator from Celery.

Django
from celery import [1]
Drag options to blanks, or click blank then click option'
Ashared_task
Btask
Cworker
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task' instead of 'shared_task' causes import errors.
Importing 'app' is incorrect for task decorators.
2fill in blank
medium

Complete the code to define a simple Celery task that adds two numbers.

Django
@shared_task
def add(x, y):
    return x [1] y
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' subtracts instead of adds.
Using '*' or '/' changes the operation to multiplication or division.
3fill in blank
hard

Fix the error in the task definition by completing the decorator correctly.

Django
@[1]_task
def multiply(x, y):
    return x * y
Drag options to blanks, or click blank then click option'
Aapp
Btask
Ccelery
Dshared
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@task_task' causes syntax errors.
Using '@celery_task' is invalid.
4fill in blank
hard

Fill both blanks to create a task that sends an email asynchronously.

Django
from celery import [1]

@[2]
def send_email(to, subject, body):
    # email sending logic here
    pass
Drag options to blanks, or click blank then click option'
Ashared_task
Btask
Capp
Dworker
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'task' and 'shared_task' causes import or decorator errors.
Using 'app' or 'worker' is incorrect here.
5fill in blank
hard

Fill all three blanks to define a periodic task that runs every minute.

Django
from celery import [1]
from celery.schedules import [2]

@[3]()

def periodic_task():
    print('Runs every minute')
Drag options to blanks, or click blank then click option'
Ashared_task
Bcrontab
Ctask
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task' instead of 'shared_task' for decorator causes errors.
Using 'app' or 'worker' is incorrect for these imports.