I have an application where, through a server, the user needs to download a CSV file and an image that is stored in the same directory as the .py file but it doesn´t work. Here are my python code:
app = Flask(__name__)
@app.route('/', methods= ['POST', 'GET'])
def result():
if request.method == 'GET':
return render_template('result.html')
elif request.method == 'POST':
if request.form['submit_button'] == 'Download CSV':
return send_file('name.csv', as_attachment=True, download_name='name.csv')
elif request.form['submit_button'] == 'Download plot':
return Flask.send_static_file('static/plot.png', as_attachment=True, download_name='plot.png')
if __name__ == '__main__':
app.run(debug = True, host='0.0.0.0')
Here are my html code:
<div class = 'wrap'>
<form method="POST">
<input type="submit" name="submit_button" value="Download CSV">
<input type="submit" name="submit_button" value="Download plot">
</form>
</div>
And here are my directories:
However, when I try to download it, I get the following error:
Thank you very much!!! I hope you can help me!