Bird
0
0

Why is it recommended to use the @shared_task decorator instead of @app.task in reusable Django apps?

hard📝 Conceptual Q10 of 15
Django - Celery and Background Tasks
Why is it recommended to use the @shared_task decorator instead of @app.task in reusable Django apps?
ABecause @app.task requires tasks to be defined in models.py
BBecause @app.task is deprecated and no longer works
CBecause @shared_task automatically runs tasks synchronously
DBecause @shared_task allows the task to be used without direct access to the Celery app instance
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between @shared_task and @app.task

    @shared_task lets tasks be defined without needing the Celery app instance directly.
  2. Step 2: Identify why this matters for reusable apps

    Reusable apps may not have direct access to the Celery app, so @shared_task is preferred.
  3. Final Answer:

    Because @shared_task allows the task to be used without direct access to the Celery app instance -> Option D
  4. Quick Check:

    @shared_task = reusable without app instance [OK]
Quick Trick: @shared_task works without Celery app instance [OK]
Common Mistakes:
MISTAKES
  • Thinking @app.task is deprecated
  • Believing @shared_task runs tasks synchronously
  • Assuming @app.task requires models.py

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes