Django:使用Apache和mod_xsendfile提供服务器文件

时间:2012-09-11 23:44:18

标签: django apache2

我无法为用户下载服务我的服务器文件。我正在使用带有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”。感谢帮助

1 个答案:

答案 0 :(得分:2)

python代码看起来对我来说,在你的apache配置中你必须配置mode_xsendfile,如下例所示:

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

还要确保正确加载mod_xsend文件。