使用Python在Bottle上的web-app中的实时值

时间:2013-09-16 12:57:32

标签: python web-applications bottle

我希望监控在网页上不断变化的实时值。因此,我将真实值模拟为我脚本上的随机值,并尝试在Bottle创建的网页上监控它。但是为了看到新值,我只需要重新加载整个页面。 我想要的是使用指定的间隔时间更新该值。它只能用Ajax吗?我怎么能用另一种方式呢?这是我的代码:

from bottle import route, run
from random import randint

@route('/monitor')
def index():
    name=randint(0,999)
    return '<b>Value is  %d!</b>' % name

if __name__ == '__main__':
    run(host='localhost', port=8080)

提前致谢。

1 个答案:

答案 0 :(得分:1)

Ajax(jquery,angular,whatever)是最合适的,但是如果你不想这样做,你可以在HTML中添加一个刷新标签,并使用它自动重新加载页面:

<meta http-equiv="refresh" content="600">