【发布时间】:2019-12-02 07:30:04
【问题描述】:
我正在尝试在我的项目中使用Channels2。这是我第一次在 Django 中遇到频道 :)
我在这里有两个主要有用且几乎完整的来源:1)youtube 上的视频DJANGO CHANNELS 2 Tutorial (V2) - Real Time 2)Read The Doc 中的频道文档
因为我不知道我的代码将来会发生什么,所以我需要您帮助我选择使用源 #1 中提到的 AsyncConsumer 或源 #2 中使用的 AsyncWebsocketConsumer 来启动Django channel app 包括通过这种方式:
from channels.generic.websocket import AsyncWebsocketConsumer
from channels.consumer import AsyncConsumer
解释:
class AsyncConsumer:
"""
Base consumer class. Implements the ASGI application spec, and adds on
channel layer management and routing of events to named methods based
on their type.
"""
class AsyncWebsocketConsumer(AsyncConsumer):
"""
Base WebSocket consumer, async version. Provides a general encapsulation
for the WebSocket handling model that other applications can build on.
"""
我使用频道的目标:尝试针对特定情况将实时聊天、通知/警报/传输数据集成到客户端。 (现在应用程序在没有 Websocket 的情况下使用 DRF)
如果您有任何建议、想法或通知,我将非常乐意倾听。非常感谢。
【问题讨论】:
标签: django websocket django-channels