Skip to content

Instantly share code, notes, and snippets.

@mpapierski
Created January 24, 2019 17:41
Show Gist options
  • Save mpapierski/956698b5b59eb724903212a2dfdaaa67 to your computer and use it in GitHub Desktop.
Save mpapierski/956698b5b59eb724903212a2dfdaaa67 to your computer and use it in GitHub Desktop.
class TestView(LoginRequiredMixin, UserPassesTestMixin, View):
model = Foo
def make_dataset(self):
"""This method returns an instance of tablib.Dataset."""
pass
def get(self, request, **kwargs):
# Create empty dataset
dataset = self.make_dataset()
response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response[
'Content-Disposition'] = 'attachment; filename="Test.xlsx"')
response.write(dataset.xlsx)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment