I have a Python CGI script script.py running on a server. It produces a CSV file as output.
I want computer-inexperienced people that don’t know about file extensions to be able to just save the file to their hard drive and use it by double-clicking.
The problem: If they now click “OK” in the save dialog of the browser, the saved file’s name is script.py, instead of script.csv.
How can I set some sort of “default filename” from within the CGI? Maybe some HTTP header trickery?
I don’t have access to the server configuration.
You need to set a
Content-Dispositionheader, with afilenameattribute. See an earlier question for some discussion.Yours would look like:
As well as setting the filename, this will tell the browser to save the file, rather than to open it inline.