Decorator to make files downloadable

1
2
3
4
5
6
7
8
def serve_download(view_func):
    def _wrapped_view_func(request, *args, **kwargs):
        response = view_func(request, *args, **kwargs)
        response['Content-Type'] = 'application/octet-stream';
        import os.path
        response['Content-Disposition'] = 'attachment; filename="%s"' % os.path.basename(kwargs['path'])
        return response
    return _wrapped_view_func

More like this

  1. X-Sendfile static file serve view by dokterbob 1 year, 4 months ago
  2. Fix for GZipMiddleware when serving files or streaming or using iterators by wojtek 2 years, 3 months ago
  3. Serve from STATIC_ROOT by popen2 8 months, 3 weeks ago
  4. Serve static media and indexes from app directories [Python2.5, Development only] by adamlofts 3 years, 5 months ago
  5. Enforce site wide login by chbrown 3 years, 3 months ago

Comments

(Forgotten your password?)