发送实时数据给客户与剑圣 [英] Send real time data to client with juggernaut
问题描述
我试图用烧瓶的juggernaut框架来发送实时信息给客户端浏览器,然后在 这是我的python代码: 我很困惑为什么没有发送给客户端浏览器。 谢谢 Juggernout已被弃用 http://blog.alexmaccaw.com/killing-a-library 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/. 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: My html page is, which inherits from a base html page: 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. Like EventSource http://www.html5rocks.com/en/tutorials/eventsource/basics/ 这篇关于发送实时数据给客户与剑圣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
import flask
from flask.views从tweetStreamsRT导入MethodView
从juggernaut导入StreamerRt
导入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)
返回self.get()
app.add_url_rule('/',view_func = View.as_view('index'),methods = ['GET','POST'])
app.debug = True
if __name__ ==__main__:
print'听取http:// localhost:%s'%PORT
app.run()
我的html页面是从基本html继承的页面:
{%extendsbase.html%}
{%importforms.htmlas forms %}
{%block page_header%}
< div class =page-header>
< h1>欢迎< / h1>
< / div>
{%endblock%}
{%block content%}
输入您要关注的活动< / h2>
< form action =/method =post>
< input type =textname =event/>
< input type =submitvalue =提交查询/>
< / form>
结果:
< pre>
< script type =text / javascriptcharset =utf-8>
var jug = new Juggernaut;
jug.subscribe(channel,function(data){
alert(Got data:+ data);});
< / script>
< / pre>
{%endblock%}
如果你关于围绕它构建应用程序,现在是切换到别的东西的正确时机。像EventSource一样 http://www.html5rocks.com/en/tutorials/eventsource/basics/ 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()
{% 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 %}