大佬教程收集整理的这篇文章主要介绍了Django 向 WebSocket 发送数据,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个项目,我希望在数据库中发生更改时更新页面的内容。我已经设置了频道并且通讯效果很好(来自某些组的用户可以在他们的组内发送和接收消息 - 一切都很好)。
现在我有后台任务在数据库中的值发生变化的特定时间运行和触发。我想要做的(如果可能的话)是将一些数据发送到某个套接字(在后台工作函数内部数据库中的数据更改的函数之后发送),并且与它相关的用户将收到消息和将执行某些操作。所以我试图找到一种发送数据的方法,但不知道如何发送。
@BACkground(schedule=30)
def room_start(room_url):
room= Room.objects.get(room_url=room_url)
room.state = "R"
room.save()
# This is where I would send some data to users and notify them of changes and perform
# actions on the frontend according to it.
# I'm not sure what the solution would be,but I was thinking of maybe sending test message to
# the socket and checking if there is an update but that doesn't seem to be the right way to do
# it. I'm not sure if maybe passing the object when calling the BACkground function Could do the
# trick but again that probably wouldn't be the best way to do it
print("ROOM STATE CHANGED TO R")
也许 websockets 甚至不是这里的解决方案,也许实施轮询之类的东西会更好,但我不确定,所以不胜感激。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Django 向 WebSocket 发送数据全部内容,希望文章能够帮你解决Django 向 WebSocket 发送数据所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。