【问题标题】:how to print string to html如何将字符串打印到html
【发布时间】:2019-09-02 11:43:02
【问题描述】:

我想进行实时数据库更新并在 html 中显示它们。

我正在使用带有此代码 sn-p 的 Jinja 模板,但它不起作用。

{{% for msg in dbmsg %}} {{ msg }}

这是我用来发送消息的代码。

class RandomThread(Thread):
    def __init__(self):
        self.delay = 1
        super(RandomThread, self).__init__()

    def randomNumberGenerator(self):
        while not thread_stop_event.isSet():
            mycursor.execute('SELECT * FROM pydb.live')
            dbmsg = mycursor.fetchall()
            mydb.commit()
            socketio.emit('newreuslt', {'result': dbmsg}, namespace='/test')
            sleep(self.delay)

    def run(self):
        self.randomNumberGenerator()

【问题讨论】:

    标签: python-3.x flask flask-socketio


    【解决方案1】:

    您不能直接在 Jinja 模板中获取 flask-socketio 消息。我建议您查看 flask-socketio examples 以了解如何包含正确的 Javascript 依赖项 (socketio) 以使其正常工作。

    【讨论】:

      猜你喜欢
      • 2014-02-09
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 2015-01-03
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多