On Tue, Nov 8, 2011 at 2:11 PM, zak2011 <zak2...@m.allo.ws> wrote: > Dear Django Users, > > tl;dr: Please tell me what strategies I might use to serve a large > static file from within Django, from views.py. > > If I want to limit access to a particular page in a Django app, I can > do something like this in views.py: > > (Note: I will use four periods to indent, because spaces or tabs might > not display properly.) > > def private_page(request): > ....if special_permissions_checking_function(request.user): > ........return render_to_response('private_page_template.html') > ....else: > ........return render_to_response('access_denied.html') > > What if I want to limit access to a large static file, instead of a > dynamically generated HTML template? > > The fastest way to do this is to tell the web server to serve the file from a protected location. Apache and nginx both have ways to signal from python code that a file should be read from disk and streamed to the user. This file doesn't have to be in a location which is accessible through a normal web request; ideally all access to it would be through your app, and you can do whatever access checks that you want to before serving it.
Look up X-SENDFILE for Apache, or X-Accel-Redirect for nginx for the details. Ian > Ideally the resulting website will be fast, but I also want to hear > options that might be low performance. > > Thank you, > > Zak > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Regards, Ian Clelland <clell...@gmail.com> -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.