小编Muk*_*osh的帖子

Laravel 5.3中的多重身份验证

如何在Laravel 5.3中为两个不同的表(用户和管理员)设置多个身份验证.

默认情况下,Laravel具有用户模型.

laravel laravel-5.3

4
推荐指数
1
解决办法
5100
查看次数

使用频道 2 向一位用户发送通知

我想使用 Channels 2 向特定的经过身份验证的用户发送通知。

在下面的代码中,我将通知作为广播发送,而不是我想向特定用户发送通知。

from channels.generic.websocket import AsyncJsonWebsocketConsumer


class NotifyConsumer(AsyncJsonWebsocketConsumer):

    async def connect(self):
        await self.accept()
        await self.channel_layer.group_add("gossip", self.channel_name)
        print(f"Added {self.channel_name} channel to gossip")

    async def disconnect(self, close_code):
        await self.channel_layer.group_discard("gossip", self.channel_name)
        print(f"Removed {self.channel_name} channel to gossip")

    async def user_gossip(self, event):
        await self.send_json(event)
        print(f"Got message {event} at {self.channel_name}")

Run Code Online (Sandbox Code Playgroud)

python django websocket python-3.x django-channels

3
推荐指数
1
解决办法
1659
查看次数