Skip to content

Commit a32b513

Browse files
Adjusted deployment asgi.py example. (#1565)
Co-authored-by: Carlton Gibson <[email protected]>
1 parent 8230e95 commit a32b513

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/deploying.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ Here's an example of what that ``asgi.py`` might look like:
2222
2323
import os
2424
25-
from channels.auth import AuthMiddlewareStack
26-
from channels.routing import ProtocolTypeRouter, URLRouter
2725
from django.conf.urls import url
2826
from django.core.asgi import get_asgi_application
2927
30-
from chat.consumers import AdminChatConsumer, PublicChatConsumer
31-
28+
# Fetch Django ASGI application early to ensure AppRegistry is populated
29+
# before importing consumers and AuthMiddlewareStack that may import ORM
30+
# models.
3231
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
32+
django_asgi_app = get_asgi_application()
33+
34+
from channels.auth import AuthMiddlewareStack
35+
from channels.routing import ProtocolTypeRouter, URLRouter
36+
37+
from chat.consumers import AdminChatConsumer, PublicChatConsumer
3338
3439
application = ProtocolTypeRouter({
3540
# Django's ASGI application to handle traditional HTTP requests
36-
"http": get_asgi_application(),
41+
"http": django_asgi_app,
3742
3843
# WebSocket chat handler
3944
"websocket": AuthMiddlewareStack(
@@ -44,7 +49,6 @@ Here's an example of what that ``asgi.py`` might look like:
4449
),
4550
})
4651
47-
4852
Setting up a channel backend
4953
----------------------------
5054

0 commit comments

Comments
 (0)