如何在每次访问Flask应用程序时重新加载它 [英] How to reload a Flask app each time it's accessed

查看:739
本文介绍了如何在每次访问Flask应用程序时重新加载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 / get_data 端点访问的烧录器应用程序,并提供一个数字作为id( 127.0.0.1:55555/get_data = 56

  @ app.route('/ get_data =< id>')
def get_vod_tree(id):
...
return render_template('index.html')

$ b b

它调用一个函数,该函数获取该id下的一些数据,并使用收集的数据创建一个json文件[static / data.json],然后返回render_template('index.html')。



在index.html中有一个对../static/data_tree.js的调用,它依次读取json文件并使用d3.js在浏览器中输出可视化。 / p>

当应用程序运行时,我在浏览器上获得相同的输出,即使我使用不同的id和json文件更改。它只有在我重新加载应用程序,然后访问网址时才有效。



我的问题是:
如何确保多个用户根据id获取不同的输出,或者当我点击终端时如何重新加载应用程序。



事后:如果多个用户使用应用程序,每次只创建一个文件

解决方案

感谢您的回答。它帮助达到这个的底部。它现在工作如下:

  @ app.after_request 
def apply_caching(response):
response。 headers ['Cache-Control'] ='无缓存,无存储,必须重新验证'
返回响应

因此,通过禁用缓存,应用程序可以将每个请求视为唯一。


I have a flask app that is accessed using the /get_data endpoint and providing a number as an id (127.0.0.1:55555/get_data=56)

@app.route('/get_data=<id>') 
def get_vod_tree(id):
    ...
    return render_template('index.html') 

It invokes a function that fetches some data under that id and creates one json file [static/data.json] with the collected data and then returns render_template('index.html').

In the index.html there is a call to ../static/data_tree.js which in turn reads the json file and outputs a visualization in the browser using d3.js.

When the app runs, I get the same output on the browser even when I use a different id and the json file changes. It only works if I reload the app and then access the url.

My question is: How can I make sure that multiple users get the different outputs according to the id or how can I reload the app when I hit the endpoint.

Afterthought: If multiple users are using the app then there is only one file created each time

解决方案

Thanks for the answers. It helped getting to the bottom of this. It works now like this:

@app.after_request
def apply_caching(response):
    response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
    return response

So by disabling the cache the application can treat each request as unique.

这篇关于如何在每次访问Flask应用程序时重新加载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆