[英]Send real time data to client with juggernaut
I have tried to use the juggernaut framework for flask in order to send real-time information to the client browser followinf the flask snippet at http://flask.pocoo.org/snippets/80/ . 我曾尝试使用烧瓶的juggernaut框架,以便在http://flask.pocoo.org/snippets/80/上的烧瓶片段中向客户端浏览器发送实时信息。
When I try to implement it for my code, it still does not provide a real-time output in the client browser. 当我尝试为我的代码实现它时,它仍然不提供客户端浏览器中的实时输出。
This is my python code: 这是我的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()
My html page is, which inherits from a base html page: 我的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 %}
I'm confused as to why nothing is sent to the client browser. 我很困惑为什么没有发送到客户端浏览器。
Thanks 谢谢
Juggernout is deprecated http://blog.alexmaccaw.com/killing-a-library If you're about to build your application around it it's the right time to switch to something else. Juggernout已被弃用http://blog.alexmaccaw.com/killing-a-library如果您要围绕它构建应用程序,那么现在是切换到其他东西的正确时机。 Like EventSource http://www.html5rocks.com/en/tutorials/eventsource/basics/ 像EventSource一样http://www.html5rocks.com/en/tutorials/eventsource/basics/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.