Skip to content

Commit 9e1e760

Browse files
authored
Use Django internal ASGI handling from Channels version 4.0.0. (#1688)
* From Channels 4.0.0 on it has no ASGI handling included but utilizes Django's own ASGI handling.
1 parent 3f89260 commit 9e1e760

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import channels
2-
3-
from channels.http import AsgiHandler
42
from channels.routing import ProtocolTypeRouter
53

6-
if channels.__version__ < "3.0.0":
7-
channels_handler = AsgiHandler
8-
else:
9-
channels_handler = AsgiHandler()
4+
try:
5+
from channels.http import AsgiHandler
6+
7+
if channels.__version__ < "3.0.0":
8+
django_asgi_app = AsgiHandler
9+
else:
10+
django_asgi_app = AsgiHandler()
11+
12+
except ModuleNotFoundError:
13+
# Since channels 4.0 ASGI handling is done by Django itself
14+
from django.core.asgi import get_asgi_application
15+
16+
django_asgi_app = get_asgi_application()
1017

11-
application = ProtocolTypeRouter({"http": channels_handler})
18+
application = ProtocolTypeRouter({"http": django_asgi_app})

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ deps =
108108

109109
django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: djangorestframework>=3.0.0,<4.0.0
110110

111-
{py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels>2
111+
{py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels[daphne]>2
112112
{py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: pytest-asyncio
113113
{py2.7,py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.2,3.0,3.1,3.2}: psycopg2-binary
114114

0 commit comments

Comments
 (0)