【发布时间】:2016-03-03 11:02:53
【问题描述】:
我正在尝试通过 url 下载文件。它通常是下载的,但问题是,当我试图打开文件时,它有 0 个字节。
有没有人遇到过这个问题,或者有想法从哪里来?
这是我的代码
def download():
file_name = "/opt/static/avatar/20/mouse.png"
response = HttpResponse(content_type='application/force-download')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(path)
return response
【问题讨论】:
-
请注明您使用的web框架?
-
您是否尝试将
content_type设置为application/binary? -
@Selcuk 框架是 Django
-
X-sendfile 是一个非标准的标头。您的具体配置是什么(应用服务器、Web 服务器、Django 版本)?
-
你的网络服务器是什么? nginx、apache 还是别的什么?
标签: python django file download