How to restart Flask application every time you access it

I have a jar application accessed via the endpoint /get_data and providing the number as id ( 127.0.0.1:55555/get_data=56 /get_data )

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

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

There is a call to index.html .. / static / data _tree.js, which in turn reads the json file and displays the visualization in the browser using d3.js.

When the application starts, I get the same output in the browser, even when I use a different identifier, and the json file changes. It only works if I restart the application and then access the URL.

My question is: How can I make sure that several users get different outputs according to the identifier or how can I restart the application when I get to the endpoint.

Further thought: if several users use the application, then only one file is created each time

0
python flask
Jul 22 '16 at 9:48
source share
2 answers

Thanks for answers. It helped to figure this out. Now it works as follows:

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

Thus, by disabling the cache, the application can process each request as unique.

+1
Jul 22 '16 at 10:55
source share

If you installed app.run(debug=True) in the / dev testing environment, it will automatically restart your Flask application every time the code changes.

To restart the application when the static file changes, use the extra_files parameter. See here .

Code example:

 extra_dirs = ['directory/to/watch',] extra_files = extra_dirs[:] for extra_dir in extra_dirs: for dirname, dirs, files in os.walk(extra_dir): for filename in files: filename = path.join(dirname, filename) if path.isfile(filename): extra_files.append(filename) app.run(extra_files=extra_files) 

Source

0
Jul 22 '16 at 10:03
source share



All Articles