Django Channels Group Send Only Sends The Message To Last Channel
I'm working on django channels-3.0.3, the group_send only sends my message to the last connected channel to the connected users times. settings ... INSTALLED_APPS = [ 'django.c
Solution 1:
Try this:
- Import
get_asgi_application
fromdjango.core.asgi
. - allow Django's ASGI application to handle traditional
http
requests by addinghttp
as key &get_asgi_application()
as the value of key in the dictionary insideProtocolTypeRouter
. - use/call the
as_asgi()
classmethod while routing theChatConsumer
consumer.
routing.py
from django.conf.urls import url
from django.core.asgi import get_asgi_application #Change No.1
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from channels.security.websocket import AllowedHostsOriginValidator, OriginValidator
from chat.consumers import ChatConsumer
application = ProtocolTypeRouter({
"http": get_asgi_application(), #Change No.2
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter([
url(r"^messages/(?P<username>[\w.@+-]+)/$", ChatConsumer.as_asgi()), #Change No.3
])
)
)
})
More Information on channels.readthedocs.io.
Post a Comment for "Django Channels Group Send Only Sends The Message To Last Channel"