Login

Tag "download"

Snippet List

HttpResponseSendfile

An HttpResponse for giving the user a file download, taking advantage of X-Sendfile if it's available, using FileWrapper if not. Usage: HttpResponseSendfile('/path/to/file.ext') To bypass the fallback: HttpResponseSendfile('/path/to/file.ext', fallback=False) This has been tested working with Lighttpd 1.4.28's mod_fastcgi.

  • download
  • sendfile
  • x-sendfile
Read More

DownloadView generic class view

Generic class view to abstract out the task of serving up files from within Django. Recommended usage is to combine it with SingleObjectMixin and extend certain methods based on your particular use case. Example usage class Snippet(models.Model): name = models.CharField(max_length = 100) slug = SlugField() code = models.TextField() from django.views.generic.detail import SingleObjectMixin class DownloadSnippetView(SingleObjectMixin, DownloadView): model = Snippet use_xsendfile = False mimetype = 'application/python' def get_contents(self): return self.get_object().code def get_filename(self): return self.get_object().slug + '.py' '''

  • view
  • download
  • class-based-views
Read More

send_file and send_data

Simple functions for downloading files - send_data sends the data directly, send_file as attachment. May need optimizing for large files.

  • files
  • download
Read More

4 snippets posted so far.