在Django提供静态文件,逻辑(保持downloadcount) [英] Serving static files with logic in django (keeping a downloadcount)

查看:118
本文介绍了在Django提供静态文件,逻辑(保持downloadcount)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,使得用户能够下载特定文件。不过,我要为每个文件保留通过将在不同的子域的静态文件那么回事通常的方式下载计数,然后让阿帕奇做繁重不是办法,以及Htt的presponseRedirecting用户一个子域名是不是一件好事,因为这时用户看到正确的下载URL,因此可以下载的文件不增加下载次数。我可以建立一个视图,然后服务于()S中的文件,但是我很担心这一点的大胖子免责声明。你会如何​​/你实现这个?我很舒尔我不是唯一一个有这个问题。

I have a site which enables the user to download certain files. However I want to keep a download count for each file so going the usual way by putting the static files on a different subdomain and then letting apache do the heavy lifting is not a way as well as HttpResponseRedirecting the user to a subdomain isn't good because then the user 'sees' the proper download url and can therefore download the file without incrementing the download count. I could just build a view which then serve()s the file however i am worried about that "big fat disclaimer". How would you/did you implement this? I am quite shure I am not the only one with that problem.

平台简介:我使用Apache和mod_wsgi的。

About the Platform: I am using apache and mod_wsgi.

感谢您

推荐答案

PSJ的答案肯定一种可行的选择是。您应该调查另一种选择是把一个反向代理服务器在前面的Apache如 Perlbal 支持的X REPROXY-URL标头。

psj's answer is definitely one viable option. Another option you should investigate is putting a reverse-proxy server in-front of apache like Perlbal which supports "X-REPROXY-URL" headers.

一旦你有了到位的反向代理服务器,而不是发送用户重定向响应,您可以发送与X-REPROXY-URL一个响应头设置为一个网址,其中代理服务器可以访问,但用户不能。然后代理服务器将您在标头中发送的位置的文件中读出,再服出来给你的客户。他们会以一种有效的方式这样做,因为你的Django应用程序服务器需要发送的所有是一个报头组的响应,它是免费的,以处理其他请求。

Once you have the reverse-proxy server in place, instead of sending the user a redirect response, you can send a response with the "X-REPROXY-URL" header set to a URL where the proxy server can access but the user can't. The proxy server will then read in the file from the location you sent in the header, and then serve it out to your client. They'll do so in an efficient way and since all your Django app server needs to send is a response with a header set, it is free to handle another request.

这篇关于在Django提供静态文件,逻辑(保持downloadcount)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆