问题描述
我尝试开发通知系统。我希望系统管理员能够将通知发送到不同的组。为此,我仅创建一个websocket连接,并且在连接套接字(登录期间)时,我要将用户添加到其所属的组中。我写的代码如下,但是我不确定它是正确的。我已经收到此错误:“ AttributeError:“ WebSocketProtocol”对象没有属性“ handshake_deferred””
class MyConsumer(AsyncWebsocketConsumer):
async def connect(self):
if self.scope["user"].is_anonymous:
await self.close()
else:
groups = await sync_to_async(list)(self.scope["user"].channel_groups.all())
for group in groups:
await self.channel_layer.group_add(group.name,self.channel_name)
await self.accept()
print("###CONNECTED")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)