Bird
0
0

What will the following async view return when called?

medium📝 Predict Output Q4 of 15
Django - Async Django
What will the following async view return when called?
from django.http import HttpResponse

async def greet(request):
    return HttpResponse('Hello Async')
AA JSON response with 'Hello Async'.
BA coroutine object instead of HttpResponse.
CA HttpResponse with content 'Hello Async'.
DAn error because HttpResponse cannot be returned from async views.
Step-by-Step Solution
Solution:
  1. Step 1: Understand async view return values

    Async views can return HttpResponse objects directly; Django handles awaiting internally.
  2. Step 2: Evaluate each option

    A HttpResponse with content 'Hello Async'. is correct. A coroutine object instead of HttpResponse. is wrong because Django awaits the coroutine. An error because HttpResponse cannot be returned from async views. is false; HttpResponse is valid. A JSON response with 'Hello Async'. is incorrect as no JSON is returned.
  3. Final Answer:

    A HttpResponse with content 'Hello Async'. -> Option C
  4. Quick Check:

    Async view returns HttpResponse normally [OK]
Quick Trick: Async views can return HttpResponse objects directly [OK]
Common Mistakes:
MISTAKES
  • Expecting coroutine instead of response
  • Thinking HttpResponse is invalid in async
  • Confusing response type with JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes