因此,通过搜索,我找到了这个讨论主题。
您可能会对三件事感兴趣。
首先是mod_python方法,
然后是mod_wsgi方法
两者看起来都不太好。
更好的是X-Sendfile标头,它不是完全标准的,但至少在apache和lighttpd中有效。
从这里开始,我们有以下内容。
@login_requireddef serve_file(request, context): if <check if they have access to the file>: filename = "/var/www/myfile.xyz" response = HttpResponse(mimetype='application/force-download') response['Content-Disposition']='attachment;filename="%s"'%filename response["X-Sendfile"] = filename response['Content-length'] = os.stat("debug.py").st_size return response return <error state>那几乎应该就是您想要的。只要确保您碰巧使用了X-Sendfile支持即可。



