Bird
0
0

What is wrong with this async view?

medium📝 Debug Q7 of 15
Django - Async Django
What is wrong with this async view?
async def view(request):
    result = some_sync_function()
    return HttpResponse(result)

Assuming some_sync_function() is a blocking call.
ACalling blocking sync function inside async view blocks the event loop.
BHttpResponse cannot be returned from async views.
CThe function should be defined with def, not async def.
DThe view must await the HttpResponse.
Step-by-Step Solution
Solution:
  1. Step 1: Understand blocking calls in async views

    Calling blocking synchronous functions inside async views blocks the event loop, negating async benefits.
  2. Step 2: Check other options

    HttpResponse can be returned directly from async views. The function is correctly defined with async def. HttpResponse is not awaitable.
  3. Final Answer:

    Calling blocking sync function inside async view blocks the event loop. -> Option A
  4. Quick Check:

    Avoid blocking calls inside async views [OK]
Quick Trick: Avoid blocking sync calls inside async views [OK]
Common Mistakes:
MISTAKES
  • Thinking HttpResponse must be awaited
  • Confusing async function definition
  • Ignoring blocking call impact

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes