Prompt user to save my desired text file name
I wish when the user clicks on a link say.
http://www.xyz.com/dynamic-text.py
The browser will prompt user to save the text file.
The following script will make browser to prompt user to save 开发者_运维技巧dynamic-text.py
. I wish to prompt user to save some-file-name.txt
. How can I do so?
dynamic-text.py
#!c:/Python27/python.exe -u
print "Content-type: text/text"
print
print "This is Text File"
You can send the Content-Disposition HTTP header:
print "Content-Type: text/plain"
print "Content-Disposition: attachment; filename=some-file-name.txt"
print
Also note that you should use the text/plain
content type instead of text/text
which, to my knowledge, doesn't exist.
精彩评论