Bird
0
0

Examine this async Django view:

medium📝 Debug Q6 of 15
Django - Async Django
Examine this async Django view:
async def sample_view(request):
    response = HttpResponse('Hello')
    await response
    return response

What is the issue with this code?
AThe response content must be awaited, not the response object
BHttpResponse must be awaited before returning
CThe view should be synchronous since it returns HttpResponse
DYou cannot await an HttpResponse object because it is not awaitable
Step-by-Step Solution
Solution:
  1. Step 1: Identify await usage

    The code tries to await response, but HttpResponse is a synchronous object.
  2. Step 2: Understand awaitable objects

    Only awaitable objects (like coroutines or async functions) can be awaited.
  3. Final Answer:

    You cannot await an HttpResponse object because it is not awaitable -> Option D
  4. Quick Check:

    HttpResponse is synchronous; awaiting it causes error [OK]
Quick Trick: Only await async functions or coroutines [OK]
Common Mistakes:
MISTAKES
  • Awaiting synchronous objects like HttpResponse
  • Assuming all objects in async views are awaitable
  • Confusing response content with awaitable tasks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes