create a "save as" function


For a Django project i’m reading two XML files with an external python script to generate some results.
For now, these results are in the form of a list of “strings”, like the lines of a text file.
I did it this way because i would like to generate a real text file but the only option i know is by opening it in the script, write lines then close it, and with this way at the end of the program i’ll already have the file saved somewhere in the project’s folders.
What i would like is to open to the user a “save as” file dialog, so he can choose the name and the location of the texte file.

How do you think i can do this ? or do you think of a other, more proper way ?

Thank you !

Keep in mind that your Django code is running in the server, not in the browser on the user’s workstation. It would be extremely bad to allow a user to specify a directory and file name on the server for a file being created on the server.

If you’re building this file and then returning it to them through an HTTP FileResponse as an attachment, then they’ll get the dialog box allowing them to specify where it’s going to be saved on their workstation and the file name, unless they’ve got their browser configured to automatically save those files in which case you have no control over it anyway.