【问题标题】:real-time values in web-app on Bottle with Python使用 Python 在 Bottle 上的 web-app 中的实时值
【发布时间】:2013-09-16 21:00:01
【问题描述】:

我想监控网页上不断变化的实时值。因此,我在脚本中将真实值模拟为随机值,并尝试在 Bottle-created 网页上对其进行监控。但为了看到新值,我只需要重新加载整个页面。 我想要的是用指定的时间间隔更新值。难道只有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)

提前致谢。

【问题讨论】:

    标签: python web-applications bottle


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 2021-03-08
      相关资源
      最近更新 更多