Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Flask更新渲染模板_Python_Web_Flask_Memcached_Refresh - Fatal编程技术网

Python Flask更新渲染模板

Python Flask更新渲染模板,python,web,flask,memcached,refresh,Python,Web,Flask,Memcached,Refresh,我使用python中的memcached存储两个数据(state) 我使用flask快速创建Web服务器。我的目标是用memcached恢复这些数据并更新到我的flask模板 mc = memcache.Client(['127.0.0.1:11211'], debug=0) app = Flask(__name__) def updateH(): state = mc.get("wc_h") if state: return "yes.png" els

我使用python中的memcached存储两个数据(state) 我使用flask快速创建Web服务器。我的目标是用memcached恢复这些数据并更新到我的flask模板

mc = memcache.Client(['127.0.0.1:11211'], debug=0)
app = Flask(__name__)

def updateH():
    state = mc.get("wc_h")
    if state:
        return "yes.png"
    else:
        return "no.png"

def updateF():
    state = mc.get("wc_f")
    if state:
        return "yes.png"
    else:
        return "no.png"

@app.route('/')
def index():    
    return render_template('index.html', hstate = updateH(), fstate = updateF())

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
app = Flask(__name__)
这工作得很好,但我不得不重新加载页面以更新视觉数据。。(就我而言,img src)
对不起我的英语。Thx

我认为您需要实现一个WebSocket,这可能会有帮助,我现在就试试,它似乎很好地解决了我的问题:)