0
0
Djangoframework~20 mins

ASGI vs WSGI in Django - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ASGI vs WSGI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main difference between ASGI and WSGI?
Choose the option that best describes the key difference between ASGI and WSGI in Django applications.
AASGI and WSGI both support asynchronous communication but differ in performance optimizations.
BWSGI supports asynchronous communication and WebSockets, while ASGI only supports synchronous HTTP requests.
CASGI supports asynchronous communication and WebSockets, while WSGI only supports synchronous HTTP requests.
DWSGI is designed for mobile apps, while ASGI is designed only for desktop web apps.
Attempts:
2 left
💡 Hint
Think about which interface allows handling multiple connections at the same time.
component_behavior
intermediate
1:30remaining
What happens when a Django app using WSGI tries to handle a WebSocket connection?
Select the correct behavior of a Django app configured with WSGI when it receives a WebSocket request.
AThe app will reject the connection because WSGI does not support WebSockets.
BThe app will handle the WebSocket connection normally using synchronous code.
CThe app will convert the WebSocket to a regular HTTP request automatically.
DThe app will crash with a syntax error.
Attempts:
2 left
💡 Hint
WSGI was designed before WebSockets existed.
📝 Syntax
advanced
2:00remaining
Identify the correct ASGI application declaration in Django
Which of the following code snippets correctly declares an ASGI application in Django?
Django
from django.core.asgi import get_asgi_application

application = ???
Aapplication.asgi()
Bget_wsgi_application()
Casgi_application()
Dget_asgi_application()
Attempts:
2 left
💡 Hint
Look for the function that returns an ASGI application instance.
state_output
advanced
2:00remaining
What is the output when running an async Django view under WSGI?
Consider an async Django view that returns a simple HTTP response. What happens when this view is run under a WSGI server?
Django
async def my_view(request):
    return HttpResponse('Hello async!')
ARaises a RuntimeWarning and runs the view synchronously, returning 'Hello async!'.
BThe server crashes with an AttributeError.
CRaises a SyntaxError because async views are not allowed.
DRuns asynchronously and returns 'Hello async!' without warnings.
Attempts:
2 left
💡 Hint
WSGI servers expect synchronous views that return HttpResponse objects directly; async views return coroutines.
lifecycle
expert
2:30remaining
How does ASGI handle multiple simultaneous connections compared to WSGI?
Select the option that best explains how ASGI manages multiple connections differently from WSGI in Django applications.
AASGI uses an event loop to handle many connections concurrently without blocking, while WSGI handles one request at a time per worker.
BWSGI uses an event loop to handle many connections concurrently, while ASGI processes requests sequentially.
CBoth ASGI and WSGI use threading to handle multiple connections simultaneously.
DASGI queues all requests and processes them one by one, while WSGI uses multiprocessing.
Attempts:
2 left
💡 Hint
Think about asynchronous programming and event loops.