Forums

Flask question on serving multiple files.

I'm a flask newbie... My current script calls a function which writes out an html file based on some REST data.

I'm then using sendfile() to either display this directly as a returned page, or give the user the option at start to change this to as_attachment and just be presented with a download of the file. This all works as expected.

I would however like to be able to: a) Do both. b) present multiple files in turn.

Ideally, what I could do is return a page that includes HTML which links to both files. The user can then click on the files to view or download in turn. I can either open the pages in new windows, or the user can click back (or I can include a "back" link on each report.

I don't understand how file pathing and permissions work. Can I (how do I?) include a link in returned HTML that allows a user to access a file that has been dynamically generated?

Looks like you should do it using javascript on the frontend (in the client's browser) and some API on the server.

You should use static file mapping if you just want to give access to a specific file. See https://help.pythonanywhere.com/pages/StaticFiles