首先在线形成一个word(用的win32com模块),另存在服务器,然后下载,代码如下,其中第四行response['Content-Encoding']:改成unicode、utf- 8、gbk都不行。
doc.SaveAs('C:\A.doc' )
wr=FileWrapper(open('C:\A.doc'))
response = HttpResponse(wr,content_type='application/msword')
response['Content-Encoding']='unicode'
response['Content-Disposition'] = ('attachment; filename=A.doc')
return response
报错如下:
UnicodeDecodeError at /
'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequenceRequest Method: POST
Request URL:
http://10.101.15.211:8000/
Django Version: 1.8.3
Exception Type: UnicodeDecodeError
Exception Value: 'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence
Exception Location: C:\Python34\lib\wsgiref\util.py in __next__, line 30
Python Executable: C:\Python34\python.exe
Python Version: 3.4.3
下面还有一行 指向之前贴的代码第三行的:
F:\mysite\fenfa\views.py in home
168. response = HttpResponse(wr,content_type='application/msword')