luc*_*luc 10 python authentication django download
我想在由django支持的网站上实现一个私有下载区域.用户必须使用适当的权限登录才能获得一些静态文件.
你有什么建议写这个功能.任何提示或技巧?
提前致谢
更新:也许是因为我的英语不好或我对这个架构缺乏了解(这就是我要问的原因)但我的问题是:如何确保静态文件(由常规网络服务器提供,不需要任何django)访问受到控制通过django身份验证.我将更仔细地阅读django文档,但我不记得该问题的开箱即用的解决方案.
Update2:我的主机提供商只允许FastCgi.
eme*_*ryc 10
所以,搜索我找到了这个讨论主题.
有三件事说你可能会感兴趣.
首先是mod_python 方法
然后是mod_wsgi 方法
这两者看起来都不那么好.
更好的是X-Sendfile标头,它不是完全标准的,但至少在apache和lighttpd中起作用.
从这里开始,我们有以下几点.
@login_required
def 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>
Run Code Online (Sandbox Code Playgroud)
这几乎应该是你想要的.只需确保在您正在使用的任何内容中启用X-Sendfile支持.