简体   繁体   English

允许新使用者查看Django渠道层中的现有数据

[英]Allow New Consumer To See Existing Data in Django Channels Layer

Im using Django Channels (and loving it) but new consumers to the layer only see data from the time they join into the future. 我正在使用Django通道(并喜欢它),但是该层的新使用者仅在加入以后才看到数据。 Is there a way for new consumers to see previous data belonging to the layer? 新使用者是否可以查看属于该层的先前数据?

You need to send the existing data either from something like the database or the cache. 您需要从数据库或缓存之类的文件中发送现有数据。 Do this on the connect method of the consumer. 在使用者的连接方法上执行此操作。 If you are using async methods you must always use an async library for IO or wrap the IO in sync_to_async or database_sync_to_async. 如果使用的是异步方法,则必须始终使用IO的异步库或将IO包装在sync_to_async或database_sync_to_async中。 This is so you don't block the event loop. 这样一来,您就不会阻塞事件循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM