I coded a pyscript-based software, which inputs a csv file. The software run well. When I change the data in the csv file, and I save it, after some attemps the changes are not updated by the py-script software, so, the calculus doesn't take into account the changes.
I tried successfully to clean the cache of the browser, but this solution is not elegant and it is not efficient. When I change the number of the port, it is ok, but this is not elegant neither.
I used run(debug=True) in the server from bottle, without a result. I added the code Bottle.reset(), but after some attemps there is an error (this code is not recognised).
I'd like to make changes in the CSV file such that the software updates the changes. I guess the problem is just bottle, something is missing.
See below my code in bottle:
from bottle import route, post, request, run, template, static_file
@route("/")
def main_page():
return static_file("WES1.html", root=f"./")
@route("/<file_name:path>")
def static_files(file_name):
return static_file(file_name, root=f"./")
@route("/images/<file_name:path>")
def images_files(file_name):
return static_file(file_name, root=f"images/")
@route("/static/<file_name:path>")
def static_files(file_name):
return static_file(file_name, root=f"static/")
@route("/data/<file_name:path>")
def data_files(file_name):
return static_file(file_name, root=f"data/")
@route("/src/<file_name:path>")
def source_files(file_name):
return static_file(file_name, root=f"src/")
run(host='localhost', port=8080, debug=True)
The problem seems to be related to the browser caching static files. Your server is serving CSV as a static file and browsers cache static content in general.
You can set cache control headers to tell the browser not to cache the CSV file. Here is how you can modify your route to set the cache control headers:
This way, you tell the browser not to cache the data and always fetch the latest file from the server.
You could also use a query parameter with a changing value (like the current timestamp) each time you request the file. This will make the browser think it's a different file and hence will not use the cached version: