How to return generated file download with Django REST Framework?
<p>I need to return generated file download as a Django REST Framework response. I tried the following:</p>

<pre><code>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-Disposition'] = u'attachment; filename="%s_%s.zip"' % (context[u'surname'], context[u'name'])
    return res
</code></pre>

<p>But it returns a msword document as <code>json</code>.</p>

<p>How do I make it start downloading as file instead?</p>