from django.http import FileResponse\n \ndef download(request):\n file = open('.\/static\/download\/\u7b80\u5386.docx', 'rb')\n response = FileResponse(file)\n response['Content-Type'] = 'application\/vnd.openxmlformats-officedocument.wordprocessingml.document'\n response['Content-Disposition'] = 'attachment;filename= '+'\u7b80\u5386'.encode('utf-8').decode('ISO-8859-1')+'.docx'\n return response\n<\/code><\/pre>\n\n\n\n\u6765\u89e3\u91ca\u4e00\u4e0bdownload\u51fd\u6570\uff1a<\/p>\n\n\n\n
1\u3001\u9996\u5148\u662f\u6253\u5f00\u5b58\u653e\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u2018.\u2019\u8868\u793a\u6839\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u4f60\u6574\u4e2adjango\u9879\u76ee\u7684\u6839\u76ee\u5f55\u3002\u6211\u7684\u201c\u7b80\u5386.docx\u201d\u6587\u4ef6\u5c31\u653e\u5728djangoProjectName\/static\/download\/\u76ee\u5f55\u4e0b\u3002<\/p>\n\n\n\n
2\u3001docx\u4f7f\u7528\u7684MIME\u7c7b\u578b\u662f application\/vnd.openxmlformats-officedocument.wordprocessingml.document\u3002<\/p>\n\n\n\n
3\u3001\u56e0\u4e3a\u6587\u4ef6\u540d\u4e2d\u6709\u4e2d\u6587\uff0c\u5982\u679c\u76f4\u63a5\u5728Content-Disposition\u4e2d\u5305\u542b\u4e2d\u6587\u4f1a\u5bfc\u81f4\u6587\u4ef6\u540d\u65e0\u6cd5\u6b63\u5e38\u663e\u793a\uff0c\u56e0\u6b64\u8981\u4ee5'\u7b80\u5386'.encode('utf-8').decode('ISO-8859-1')<\/code>\u7684\u5f62\u5f0f\u8fdb\u884c\u8f6c\u7801\u3002<\/p>\n\n\n\n\u7f51\u4e0a\u641c\u5230\u5e38\u7528\u7684\u6709\u4e09\u79cd\u65b9\u6cd5\u5b9e\u73b0\u6587\u4ef6\u4e0b\u8f7d\uff0c\u6211\u8fd9\u8fb9\u5c31\u8bd5\u4e86\u8fd9\u4e00\u79cd\uff0c\u5176\u4ed6\u4f60\u53ef\u4ee5\u81ea\u5df1\u53bb\u641c\u4e00\u4e0b\u7136\u540e\u8bd5\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u672c\u6587\u8bb0\u5f55\u4e00\u4e0b\u5728python3 django web\u5f00\u53d1\u4e2d\uff0c\u4e0b\u8f7d\u6587\u4ef6\u65f6\u6587\u4ef6\u540d\u4e3a\u4e2d\u6587\uff0c\u51fa\u73b0\u4e71\u7801\u7684\u89e3\u51b3\u65b9\u6848\u3002 \u524d\u7aef\uff1a […]<\/p>\n","protected":false},"author":1,"featured_media":46299,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[289,146,283,186],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/posts\/46632"}],"collection":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/comments?post=46632"}],"version-history":[{"count":0,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/posts\/46632\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/media\/46299"}],"wp:attachment":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/media?parent=46632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/categories?post=46632"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/tags?post=46632"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}