http推送django comet
我想制作一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该避免 HTTP 轮询。原因如下:
setInterval
的频率与 Web 应用程序上的用户数量相结合将导致大量资源消耗。如果您浏览了此演示文稿 您将看到使用 Push 的一些相当引人注目的数字(注意:此示例使用托管服务,但托管您自己的实时服务器并且使用 Push 也具有类似的好处setInterval
调用应用中显示的数据可能会出现数据不足的情况。使用推送技术意味着新数据可用时,它可以立即推送并显示在您的应用程序中。您不希望用户在查看应用程序时认为自己看到了正确的信息,但实际上并非如此。您应该回答以下 StackOverflow 问题:
对于 Python/Comet请参阅:
我建议你也开始考虑“WebSockets”以及“Comet”。现在,大多数 Comet 服务器更喜欢在可能的情况下使用 WebSocket 连接。
如果您不想安装和管理自己的 Comet/WebSocket 解决方案,那么您可以使用 实时托管服务,它允许您使用 REST API 通过它们推送数据,您的客户端可以通过嵌入 JavaScript 库并编写少量代码来订阅和接收事件来接收事件。
I think you should avoid HTTP Polling. Here's why:
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)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.
步骤非常简单:
setInterval()
的 JavaScript 的模板,该模板将处理对视图的 AJAX 请求并呈现接收到的数据。 (我建议使用 JQuery,因为它有详细的文档记录并且广泛使用)。
The steps are quite straightforward:
setInterval()
that willproceed AJAX requests to the view and render recieved data. (I'd suggest using JQuery as it's well documented and widespread).