Bird
0
0

Identify the error in this Django async view:

medium📝 Debug Q14 of 15
Django - Async Django
Identify the error in this Django async view:
async def my_view(request):
    result = slow_function()
    return JsonResponse({'data': result})
AMissing await before slow_function() call
BFunction should not be async
CJsonResponse cannot be returned from async views
DRequest parameter is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check async function calls

    In async views, calling an async function requires await to pause until it finishes.
  2. Step 2: Identify missing await

    The code calls slow_function() without await, so it returns a coroutine object, not the result.
  3. Final Answer:

    Missing await before slow_function() call -> Option A
  4. Quick Check:

    Async calls need await = C [OK]
Quick Trick: Async calls must use await [OK]
Common Mistakes:
MISTAKES
  • Forgetting to await async functions
  • Thinking JsonResponse is invalid in async
  • Assuming async views don't take request

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes