Using Django Server Sent Events with Database post save

一世执手 提交于 2019-12-04 04:48:45

Django is build around the request/response cycle which means that it doesn't work well with websockets or even SSE. In your example there is no way to propagade the post_save signal to the view unless you use subscribe to a queue (rabbitmq, redis pubsub) in the view and send data in the signal handler.

Consider other solutions to push from the server:

  • Long polling
  • Django channels
  • An asynchronus solution like nodejs or tornado instead or alongside Django

Read about signals. https://docs.djangoproject.com/en/dev/topics/signals/ In this case, you should use request_started and post_save signals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!