0

I have a flask app in which I have a front end html with multiple features.

This front end html template has a "download button" to download a file.

This is how I am triggering a download:

$('#download_excel').attr('onClick',"window.open('/static/excel.xlsx')");

download_excel corresponds to a bottom to download a file. This works fine.

But, if I move my excel.xlsx file to a different folder say "download" and modify the above line to this:

$('#download_excel').attr('onClick',"window.open('/download/excel.xlsx')");

This show no file here: (http://127.1.1.1:5555/download/excel.xlsx)

Why? what is the difference?

Tariqul Islam
  • 347
  • 4
  • 18
Tery
  • 3
  • 2

2 Answers2

0

The problem is that Flask only serves files from the static folder. You have to specify another static folder path as described here: https://stackoverflow.com/a/9519004/5868802

Dom
  • 734
  • 3
  • 8
0

This is because Flask has a default endpoint for static files (files accessible publicly) at /static. This endpoints binds to directory static in your project folder.

You can rebind this endpoint in Flask constructor:

Flask(__name__, static_url_path="/download", static_folder='download')
Phoenix Himself
  • 1,037
  • 10
  • 17