????file_path?=?os.path.join(settings.COURSE_RELATED,?str(courseid),?'courseware',?'課件.zip')
????????if?os.path.exists(file_path):
????????????with?open(file_path,?"rb")?as?file_zip:
????????????????data?=?file_zip.read()
????????????response?=?HttpResponse(data,?content_type='application/zip;charset=utf-8')
????????????response['Content-Disposition']?=?'attachment;?filename=kejian.zip'
????????????return?response
????????????#?response?=?StreamingHttpResponse(file_iterator(file_path))
????????????#?response['Content-Type']?=?'application/octet-stream'
????????????#?response['Content-Disposition']?=?'attachment;filename="{0}"'.format('kejian')
????????????#?return?response
????????else:
????????????return?Response({'error_no':?-1,?'userinfo':?True,?'error_msg':?"該課程沒(méi)有課件哦"})
????else:
????????return?Response({'error_no':?-1,?'error_msg':?"參數(shù)錯(cuò)誤"})
except:
????return?Response({'error_no':?-1,?'error_msg':?"下載出錯(cuò),稍后再試"})
python下載優(yōu)秀作業(yè)的例子,前端老是無(wú)法正常下載
清心流易
2018-08-22 12:09:27