用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()依舊得到相同訊息,
請高手相助!