django / channels

Developer-friendly asynchrony for Django

Home Page:https://channels.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'NoneType' object has no attribute 'group_add

Dhiraj1424 opened this issue · comments

I am getting AttributeError: 'NoneType' object has no attribute 'group_add' error again and again I also tried to use layers but I also got an error.

from channels.generic.websocket import WebsocketConsumer
from asgiref.sync import async_to_sync
import json
class TestConsumer(WebsocketConsumer):

def connect(self):
self.room_name="test_consumer"
self.room_group_name="test_consumer_group"
async_to_sync(self.channel_layer.group_add) (
self.room_name, self.room_group_name
)
self.accept()
self.send(text_data=json.dumps({'status':'you are conn'}))

def recive(self):
pass

def disconnect(self):
pass
asgi.py
from django.urls import path
from home.consumers import*
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
application = get_asgi_application()

WS_PATTERNS=[
path('ws/test/',TestConsumer.as_asgi()),

]
application=ProtocolTypeRouter({
'websocket':URLRouter(WS_PATTERNS)
})

commented

In the other issue it was mentioned the problem was in settings.CHANNEL_LAYERS. How does this settings value looks like in your case?