Saturday, January 31, 2015

Re: Restrict downloading files in Django?

On Sun, Feb 1, 2015 at 1:33 AM, Javier Guerra Giraldez <> wrote:
On Sat, Jan 31, 2015 at 11:52 AM, Robert Rössler <> wrote:
> what is the best way to restrict downloading files only to authorized users?

it's not hard to do if you manage the file downloading with a view.

of course, file serving within Django is very inefficient, your
webserver (Apache, nginx, etc.) is far more efficient at this.

so, the solution is to write a view that looks like it's serving the
file (after checking for authorization), but instead of actually
serving, delegates the job to the webserver.  check X-Accel-Redirect
(nginx) or X-Sendfile (apache)

The X-Sendfile (or analog) approach is the right way to go - there are even Django apps that can help manage this process. See:

For a recent blog talking walking through the process.

Russ Magee %-)

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment