gpt4 book ai didi

python - 使用 Juggernaut 向客户端发送实时数据

转载 作者:行者123 更新时间:2023-11-28 17:49:25 25 4
gpt4 key购买 nike

我尝试使用 flask 的主宰框架,以便按照 http://flask.pocoo.org/snippets/80/ 的 flask 片段向客户端浏览器发送实时信息。 .

当我尝试为我的代码实现它时,它仍然没有在客户端浏览器中提供实时输出。

这是我的 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()

我的 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 %}

我很困惑为什么什么都没有发送到客户端浏览器。

谢谢

最佳答案

Juggernout 已弃用 http://blog.alexmaccaw.com/killing-a-library如果您打算围绕它构建您的应用程序,那么现在是切换到其他东西的最佳时机。喜欢 EventSource http://www.html5rocks.com/en/tutorials/eventsource/basics/

关于python - 使用 Juggernaut 向客户端发送实时数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13038376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com