开发者

Protecting static files from non logged in users in Django

开发者 https://www.devze.com 2023-03-01 07:18 出处:网络
I have an existing site with a number of docum开发者_JAVA百科ents being served staticly. Client wants to add login protection to the site - not a problem using django_auth. However, the files being se

I have an existing site with a number of docum开发者_JAVA百科ents being served staticly. Client wants to add login protection to the site - not a problem using django_auth. However, the files being served from apache are still downloadable?

Is there a way to restrict access?

Ideally, this would require the path to these docs not changing on the site.

Was thinking of removing the alias from the apache config and having that route to a view that has the @login_required decorator on it, and then forwarding on.


See Having Django serve downloadable files on how to set up Django to work with Apache X-Sendfile. You can wrap the X-Sendfile header sending with some authentication checks and you should be good to go.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号