如何使用Django REST框架实现实时更新?

时间:2022-01-04 03:54:48

I have a client app that needs to be synchronized tightly with the server. So far, I've been using polls to retrieve the data from my REST Framework views. But the amount of requests is now too large, and I need to move towards a server push option instead. I've looked at a few options, such as Pusher, Redis/PubNub...but there are a lot of options, and very few recent documentation about it.

我有一个客户端应用程序需要与服务器紧密同步。到目前为止,我一直在使用poll从我的REST框架视图中检索数据。但是现在请求的数量太大了,我需要转向服务器推送选项。我看了一些选项,比如Pusher, Redis/PubNub…但是有很多选择,而且很少有关于它的最新文档。

What would be the best way to implement real time with the django-rest-framework views?

使用django-res -framework视图实现实时的最佳方式是什么?

3 个解决方案

#1


1  

I'm haven't tried it, but I think DRF + Django Channels + Websocket will do the job. I know this is an old thread, so I guess this will help other people having the same problem.

我还没试过,但是我认为DRF + Django通道+ Websocket可以完成这项工作。我知道这是一条老掉牙的思路,所以我想这将有助于其他有同样问题的人。

如何使用Django REST框架实现实时更新?

Read: https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django

阅读:https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django

#2


0  

Not familiar with Django as a framework, but I'd highly recommend websockets for real time updates from the server. The typical approach is to use a combination of REST and WS:

不熟悉Django作为一个框架,但是我强烈建议websockets从服务器上实时更新。典型的方法是使用REST和WS的组合:

State change on Client -> HTTP POST -> Server
                Client <- Websocket <- State change on server

#3


0  

DRF will not do the job.

DRF不会做这个工作。

I suggest using Pusher or PubNub. Working with them is really easy. Another option is Socket.io.

我建议使用推式或阴式。和他们一起工作真的很容易。另一个选择是socket . io。

What these services offer is push notification to your client app. Once notified, your app could request the resurces needed from DRF.

这些服务提供的是推送通知到你的客户端应用程序。一旦收到通知,你的应用程序就可以请求从DRF中重新出现。

#1


1  

I'm haven't tried it, but I think DRF + Django Channels + Websocket will do the job. I know this is an old thread, so I guess this will help other people having the same problem.

我还没试过,但是我认为DRF + Django通道+ Websocket可以完成这项工作。我知道这是一条老掉牙的思路,所以我想这将有助于其他有同样问题的人。

如何使用Django REST框架实现实时更新?

Read: https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django

阅读:https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django

#2


0  

Not familiar with Django as a framework, but I'd highly recommend websockets for real time updates from the server. The typical approach is to use a combination of REST and WS:

不熟悉Django作为一个框架,但是我强烈建议websockets从服务器上实时更新。典型的方法是使用REST和WS的组合:

State change on Client -> HTTP POST -> Server
                Client <- Websocket <- State change on server

#3


0  

DRF will not do the job.

DRF不会做这个工作。

I suggest using Pusher or PubNub. Working with them is really easy. Another option is Socket.io.

我建议使用推式或阴式。和他们一起工作真的很容易。另一个选择是socket . io。

What these services offer is push notification to your client app. Once notified, your app could request the resurces needed from DRF.

这些服务提供的是推送通知到你的客户端应用程序。一旦收到通知,你的应用程序就可以请求从DRF中重新出现。