1
Size: a a a
1
МП
async def connect(self):
await self.accept()
# This actually subscribes the requesting socket to the
# named group:
group_name = self._get_user_group()
if group_name:
await self.channel_layer.group_add(
group_name,
self.channel_name,
)
МП
def _get_user_group(self):
user = self.scope.get('user', None)
if user is not None and user.is_authenticated:
return user.layer_name
return ''
МП
МП
1
АМ
АМ
1
N
1
class WSConsumer(WebsocketConsumer):
def connect(self):
self.accept()
self.send('connected to WS')
class
WSConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.accept()
await self.channel_layer.group_add("stations", self.channel_name)
self.send('connected to WS')
Почему 2 вариант не работает?N
1
N
1
N
1
N