0

I am trying to create a web page where the user inputs info, submits it, and then a chart based on the submitted info shows up on the web page. My issue is that the chart image that is displayed does not update, and just stays static, even after the user info changes.

To save the chart, I use:

plt.savefig('images/chart.png')

The Flask portion of the code is:

app = Flask(__name__, static_url_path = "", static_folder = "")
@app.route('/', methods=['GET', 'POST'])
def chart():
    if request.method == "POST":
        req = request.form
        ...
    return render_template('index.html')

if __name__ == "__main__":
    app.run()

An in index.html:

<img src="{{ url_for('static', filename = '/images/chart.png') }}">

If I go to the location where the image is being saved, I see the new chart, but on the webpage, nothing changes.

sbd
  • 27
  • 6

1 Answers1

0

Are you caching images? Try clearing your cache and see if that does the trick?

For a quick cache clear on the page you can hold CTRL + the refresh button on chrome

PurpSchurp
  • 581
  • 5
  • 14
  • 1
    Yes, that does now show the updated image!! Thank you. How do I make it so that it happens automatically though? – sbd Sep 27 '20 at 06:22
  • @sbd Well I'm not quite sure what your architecture looks like, however just google it for your system. You can google something like "How do I not cache images in _" however I suspect it could have something to do with declaring "static" in the image source, but I am not sure (also don't forget to mark as answer :D) – PurpSchurp Sep 27 '20 at 06:25
  • Changing the name would work, if you have some specific userId for unique identifier you could tack onto the end of the image name, and reference it later that would work :) – PurpSchurp Sep 27 '20 at 06:26
  • If you are using flask, it seems like others have answers for that out there. maybe something like https://stackoverflow.com/questions/34066804/disabling-caching-in-flask – PurpSchurp Sep 27 '20 at 06:29