Created
January 24, 2019 17:41
-
-
Save mpapierski/956698b5b59eb724903212a2dfdaaa67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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