Bird
0
0

You want to improve your Django app's performance by using async views for slow database queries and external API calls. Which approach best uses async to avoid blocking?

hard📝 Application Q15 of 15
Django - Async Django
You want to improve your Django app's performance by using async views for slow database queries and external API calls. Which approach best uses async to avoid blocking?
AKeep views synchronous but run slow tasks in separate threads
BUse <code>async def</code> views and <code>await</code> both slow DB queries and API calls
CUse async views but call slow DB queries without await
DConvert all code to async even if it is fast and simple
Step-by-Step Solution
Solution:
  1. Step 1: Identify async usage for slow tasks

    Async views with await let Django pause only on slow tasks like DB queries or API calls, freeing the server to handle others.
  2. Step 2: Evaluate options for best async practice

    Use async def views and await both slow DB queries and API calls correctly uses async views and awaits slow operations. Keep views synchronous but run slow tasks in separate threads uses threads which is less efficient. Use async views but call slow DB queries without await misses await causing bugs. Convert all code to async even if it is fast and simple wastes async on fast code.
  3. Final Answer:

    Use async def views and await both slow DB queries and API calls -> Option B
  4. Quick Check:

    Await slow tasks in async views = B [OK]
Quick Trick: Await slow tasks in async views for best speed [OK]
Common Mistakes:
MISTAKES
  • Not awaiting slow async calls
  • Using threads instead of async for IO
  • Making all code async unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes