2

我在为用户下载提供服务器文件时遇到问题。我正在使用带有 mod_xsendfile 的 Apache。首先,如果我尝试在开发服务器上下载文件,则该文件为 0 字节。其次,如果我尝试使用 Apache 提供文件,我会收到错误

SuspiciousOperation:尝试访问 ***** 在行 document.file.path 上被拒绝

file_name = document.file.name          
response = HttpResponse(mimetype='application/force-download')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = document.file.path
return response

我已将 mod_xsend 配置为“Xsend On”。感谢帮助

4

1 回答 1

2

python代码对我来说看起来很糟糕,在你的apache配置中你必须像这个例子一样配置mode_xsendfile:

<Files *.*>
XSendFile on
XSendFilePath /absolute/path/to/your/files
</Files>

还要确保正确加载了 mod_xsendfile。

于 2012-09-12T07:33:11.390 回答