from django.http import JsonResponse, Http404,FileResponse
def download(request):
try:
response =FileResponse(open(BASE_DIR + '\\static\\uploadfiles\\模板文件.xls', 'rb'))
response['Content-Type'] = "application/octet-stream"
response['Content-Disposition'] = 'attachment; filename = 模板文件.xls'.encode('utf-8', 'ISO-8859-1')
return response
except Exception:
raise Http404
需要加编码encode(‘utf-8’, ‘ISO-8859-1’)