How to return generated file download with Django REST Framework?
问题 I need to return generated file download as a Django REST Framework response. I tried the following: def retrieve(self, request, *args, **kwargs): template = webodt.ODFTemplate('test.odt') queryset = Pupils.objects.get(id=kwargs['pk']) serializer = StudentSerializer(queryset) context = dict(serializer.data) document = template.render(Context(context)) doc = converter().convert(document, format='doc') res = HttpResponse( FileWrapper(doc), content_type='application/msword' ) res['Content