Oluşturulan dosya indirme işleminin bir Django REST Framework yanıtı olarak geri dönmesi gerekiyor.Django REST Framework ile oluşturulan dosya indirme nasıl geri alınır?
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
Ama json
gibi bir Msword belgesi döndürür: Aşağıdaki çalıştı.
Dosya yerine indirmeye nasıl başlayabilirim?
indirebilmeli mi? –
@ PiyushS.Wanare tam olarak – Viktor
Dosya oluşturulduktan sonra, eğer web sunucunuzdan (Django kodu, yetkilendirme, vb.) Herkes tarafından erişilebiliyorsa, 302 Yönlendirme yanıtı gönderebilirsiniz. – Owen