Bird
0
0

In Django's asgi.py, which import is necessary to correctly initialize an ASGI application?

easy📝 Syntax Q3 of 15
Django - Async Django
In Django's asgi.py, which import is necessary to correctly initialize an ASGI application?
Afrom channels.routing import ProtocolTypeRouter
Bfrom django.core.wsgi import get_wsgi_application
Cfrom django.core.asgi import get_asgi_application
Dfrom django.http import HttpResponse
Step-by-Step Solution
Solution:
  1. Step 1: Identify ASGI import

    The correct import for ASGI applications in Django is get_asgi_application from django.core.asgi.
  2. Step 2: Exclude WSGI import

    get_wsgi_application is for WSGI, not ASGI, so from django.core.wsgi import get_wsgi_application is incorrect.
  3. Step 3: Other options

    from channels.routing import ProtocolTypeRouter is related to Channels routing but not the basic ASGI application import. from django.http import HttpResponse is unrelated.
  4. Final Answer:

    from django.core.asgi import get_asgi_application -> Option C
  5. Quick Check:

    ASGI apps require get_asgi_application import [OK]
Quick Trick: Use get_asgi_application from django.core.asgi for ASGI apps [OK]
Common Mistakes:
MISTAKES
  • Importing get_wsgi_application instead of get_asgi_application
  • Confusing Channels routing import with ASGI app import
  • Using HTTP response imports in asgi.py

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes