Bird
0
0

Identify the error in this Django async view:

medium📝 Debug Q6 of 15
Django - Async Django
Identify the error in this Django async view:
async def my_view(request):
    result = fetch_data()
    return JsonResponse({'result': result})
Afetch_data() must be synchronous
BMissing await before fetch_data()
CAsync views cannot return JsonResponse
DRequest parameter is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check async function call

    Async functions must await other async calls to avoid coroutine objects.
  2. Step 2: Identify missing await

    fetch_data() is likely async; missing await means result is a coroutine, not data.
  3. Final Answer:

    Missing await before fetch_data() -> Option B
  4. Quick Check:

    Await async calls = C [OK]
Quick Trick: Always await async calls inside async views [OK]
Common Mistakes:
MISTAKES
  • Forgetting await keyword
  • Thinking async views can't return JsonResponse
  • Ignoring function parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes