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. TemplateZipFile by fcurella 1 year, 5 months ago
  2. A view for downloading attachment by achimnol 3 years, 8 months ago
  3. DownloadView generic class view by ckniffen 1 year, 8 months ago
  4. Accept Header Middleware by kioopi 5 years, 1 month ago
  5. Caching XHTML render_to_response by smoonen 4 years, 10 months ago

Comments

(Forgotten your password?)