【发布时间】:2018-02-14 15:51:41
【问题描述】:
我正在使用 django 1.11.2,我想查看可下载文件。单击链接后,文件正在下载,但文件为空,而不是 png,我收到的是空的 txt 文件。
def download_file(request, uuid):
response = HttpResponse(content_type='application/force-download')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(models.DownloadLink.objects.get(uuid=uuid).download_file.file)
response['Content-Length'] = 'http://{}{}'.format(Site.objects.get_current(), models.DownloadLink.objects.get(uuid=uuid).download_file.file.url)
return response
编辑:
这里response['Content-Length'] 的值是http://127.0.0.1:8000/media/filer_public/49/54/4954a7bb-8ad3-4679-9248-bffc7d186ca8/photo-105221.jpeg
【问题讨论】:
标签: python django file view download