文章详情页
python - Django利用dwebsocket实现后台数据更新实时更新到前端?
浏览:95日期:2022-09-01 13:50:55
问题描述
实现的功能是django后台数据更新之后,例如说一个群组人员增加,不刷新页面实现推送消息的功能,但是不是很懂dwebsocket的机制:
给的实例代码中:
@accept_websocketdef echo(request): if request.is_websocket:lock = threading.RLock()try: lock.acquire() clients.append(request.websocket) for message in request.websocket:if not message: break for client in clients: client.send(message)finally: clients.remove(request.websocket) lock.release()
client.send()传递的是一个什么参数呢?如何从后端发送更新的消息呢?
问题解答
回答1:不是应该前端直接定时请求的么?
相关文章:
1. css - 移动端 line-height安卓错位,苹果机正常用,缩放解决了,可是又出来了占位的问题2. mysql begin work语句是干嘛的?3. javascript - 移动端css动画播放状态暂停在ios不起作用 animation-play-state4. node.js - 函数getByName()中如何使得co执行完后才return5. javascript - vue $set 整个数组6. docker-compose中volumes的问题7. 微信开放平台 - ios APP能不能打开微信然后通过微信跳转到指定的URL?8. 小程序怎么加外链,语句怎么写!求救新手,开文档没发现9. 新手 - Python 爬虫 问题 求助10. Mac环境下QT编译MySQL驱动屡次失败?如何?
排行榜
