Python Flask: Download the file generated on the fly And print the answer

I followed the tutorial to flush a file generated on the fly in Flask. Now I want to display the message using the same data that was used to create the file. This is a large data set, and I can not afford to download it both to create a file and to print the result on the page.

Unlike In Flask, how can I redirect the template and show the message after send_file returns in the form? I do not want redirects or updates. Is it possible to send both a file and an HTML response when loading a single page?

I tried to use a generator, but had no success.

I am using Heroku.

+4
source share
1 answer

You are trying to return a "multi-page HTTP response" with an HTML part and another part (file). After a quick research, I'm not sure that such a thing exists, and if it does the way it is supported / implemented in browsers.

In a slightly different way, to respond to the "classic" HTML response, which was then to launch a second request - an XHR call when loading a document, for example, to start downloading a file.

On the server side, you will need to save the contents of the file, I am not very familiar with Heroku, but I think you could use a key value, for example Redis, or even a dedicated service, such as Amazon S3.

0

Source: https://habr.com/ru/post/1531458/


All Articles