Snippet List
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
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
4 snippets posted so far.