Должно позволять сохранять в StringIO() объект, его можно сразу отдать в ответе. Посмотрите документацию по этой библиотеке.
Как-то так http://djbook.ru/forum/topic/184/#post-1204
Спасибо, разобрался!
вот код, если кому то поможет :
from django.http import HttpResponse
from docx import Document
from .models import User_Tests
from cStringIO import StringIO
def generate_docx(request):
document = Document()
# u('тут добавляем в документ все что там нужно как в доке на python-docx')
f = StringIO()
document.save(f)
length = f.tell()
f.seek(0)
response = HttpResponse(
f.getvalue(),
content_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
)
response['Content-Disposition'] = 'attachment; filename=test_result.docx'
response['Content-Length'] = length
return response