烧瓶架可以从服务器向客户端浏览器发送实时数据吗?

use*_*628 14 python web-applications comet juggernaut flask

我想知道如何(如果有的话)烧瓶执行长轮询,因此服务器可以通过连接发送数据到客户端.例如,如果服务器通过流式api接收到Twitter提要,那么它将如何传递给客户端浏览器?

我知道你不能在这种情况下使用flask.flash.

谢谢

谢谢你的例子.我查看了这些示例,当我尝试为我的代码实现它时,它仍然没有在客户端浏览器中提供实时输出.

我使用juggernaut和redis将它基于烧瓶片段().这是我的python代码:

import flask
from flask.views import MethodView
from tweetStreamsRT import StreamerRt 
from juggernaut import Juggernaut


app = flask.Flask(__name__)
app.secret_key = "xxxxx"
PORT = 8080

class View(MethodView):

    def get(self):
        return flask.render_template('index.html')

    def post(self):
        results = StreamerRt().filter(track=[flask.request.form['event']])            
        jug = Juggernaut()
        jug.publish('channel', results)
        return self.get()


app.add_url_rule('/', view_func = View.as_view('index'), methods=['GET', 'POST'])
app.debug = True

if __name__ == "__main__":
    print 'Listening on http://localhost:%s' % PORT
    app.run()
Run Code Online (Sandbox Code Playgroud)

我的html页面是继承自基本html页面的:

{% extends "base.html" %}
{% import "forms.html" as forms %}


{% block page_header %}
  <div class="page-header">
    <h1>Welcome</h1>
  </div>
{% endblock %}
{% block content %}
  <h2>Enter the Event you would like to follow</h2>
      <form action="/" method="post">
            <input type="text" name="event" />
            <input type="submit" value="Submit Query" />
          </form>
            Results:
            <pre>
                <script type="text/javascript" charset="utf-8">
                    var jug = new Juggernaut;
                    jug.subscribe("channel", function(data){
                    alert("Got data: " + data);});
                </script>

            </pre> 
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

我仍然对为什么没有发送到客户端浏览器感到困惑.

谢谢