作者jcjan (None)
看板Python
标题[问题] django 下载 pdf
时间Wed Mar 28 16:31:31 2018
用django写了一个网站,
需让远端下载pdf档,
程式码如下
def download(request):
with open('f:/test.pdf','r') as f:
response=HttpResponse(f.read(),content_type='application/pdf')
response['Content-Disposition'] = 'attachment;filename=test.pdf'
在f.read()发生错误,
'cp950' codec can't decode byte 0x9c in position 519: illegal multibyte
sequence
我用FileWrapper(f)取代f.read()依旧得到相同讯息,
请高手相助!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.113.26.199
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1522225894.A.6E2.html
1F:→ OGCKM: open file 改参数成rb, r是开文字档用的 03/28 16:56
2F:→ jcjan: 感恩!! 03/28 17:05