I am writing a script which will run on my server. Its pu开发者_开发百科rpose is to download the document. If any person hit the particular url he/she should be able to download the document. I am using urllib.urlretrieve but it download document on the server side not on the client. How to download in python at client side?
If the script runs on your server, its purpose is to serve a document, not to download it (the latter would be the urllib
solution).
Depending on your needs you can:
- Set up static file serving with e.g. Apache
- Make the script execute on a certain URL (e.g. with mod_wsgi), then the script should set the
Content-Type
(provides document type such as "text/plain") andContent-Disposition
(provides download filename) headers and send the document data
As your question is not more specific, this answer can't be either.
Set the appropriate Content-type
header, then send the file contents.
If the document is on your server and your intention is that the user should be able to download this file, couldn't you just serve the url to that resource as a hyperlink in your HTML code. Sorry if I have been obtuse but this seems the most logical step given your explanation.
You might want to take a look at the SocketServer module.
精彩评论