http推送django comet

发布于 2024-12-09 18:05:46 字数 166 浏览 0 评论 0原文

我想制作一个 django 服务器来刷新您访问数据库的内容,如果想法是首先让用户看到数据库的当前内容,并且当山谷变成新内容时,该内容就会出现并放置在以前的内容而不重新加载页面,在网站的另一部分是让您在新内容到达数据库时更改当前内容?

evserver更清晰是我的选择,但实在不知道怎样做才最简单高效?

I want to make a django server to refresh the content that you approach the database, if the idea is to first make the user see the current contents of the database and as the valley became the new content, this content comes and is placed above the previous content without reloading the page, in another part of the site is to make you change the current content with the new as it gets to the database?

evserver clearer is my choice, but really do not know how and what would be the most simple and efficient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

病女 2024-12-16 18:05:46

我认为你应该避免 HTTP 轮询。原因如下:

您应该回答以下 StackOverflow 问题:

对于 Python/Comet请参阅:

我建议你也开始考虑“WebSockets”以及“Comet”。现在,大多数 Comet 服务器更喜欢在可能的情况下使用 WebSocket 连接。

如果您不想安装和管理自己的 Comet/WebSocket 解决方案,那么您可以使用 实时托管服务,它允许您使用 REST API 通过它们推送数据,您的客户端可以通过嵌入 JavaScript 库并编写少量代码来订阅和接收事件来接收事件。

I think you should avoid HTTP Polling. Here's why:

  • if the frequency of the setInterval combined with the number of users on your web app is going to lead to a big resource drain. If you go through slides 9 to 19 in this presentation you'll see some quite dramatic figures for using Push (Note: this example uses a hosted service but hosting your own realtime server and using Push also has similar benefits)
  • between setInterval calls the data displayed in your app is potentially out of data. Using a Push technology means the instant that new data is available it can be push and displayed in your app. You don't want users looking at an app and thinking they are seeing correct information when they are not.

You should take a the following StackOverflow questions:

For Python/Comet see:

I'd recommend you also start considering "WebSockets" as well as "Comet". Most Comet servers now prefer to use a WebSocket connection when possible.

If you'd prefer to avoid installing and managing your own Comet/WebSocket solution then you could use a realtime hosted service which will allow you Push data through them using a REST API and your clients can receive events by embedding a JavaScript library and writing a small about of code to subscribe and receive the event.

仙女 2024-12-16 18:05:46

步骤非常简单:

  1. 编写一个模型来将数据存储在数据库中
  2. 编写一个视图,根据 POST 请求生成 JSON 序列化数据。
  3. 编写一个包含带有 setInterval() 的 JavaScript 的模板,该模板将
    处理对视图的 AJAX 请求并呈现接收到的数据。 (我建议使用 JQuery,因为它有详细的文档记录并且广泛使用)。

The steps are quite straightforward:

  1. Write a model to store data in DB
  2. Write a view that will generate JSON-serialized data upon POST request.
  3. Write a template that will contain JavaScript with setInterval() that will
    proceed AJAX requests to the view and render recieved data. (I'd suggest using JQuery as it's well documented and widespread).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文