Django view to export vsdx format

I am currently working on a view that needs to export visio files. I already have a view that exports doc files (see below), but not sure how to do that to return vsdx file as response

from docx import Document

def get(self, request, *args, **kwargs):
    document = Document()
    document.add_heading('Document Title', 0)

    response = HttpResponse(
        content_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document')
    response['Content-Disposition'] = 'attachment; filename=download.docx'
    document.save(response)

    return response

I'm aware that I need to update the content_type, and the way I need to open the file, but I've tried a few things and the response provided doesn't seem to open properly

Any help is appreciated

from vsdx import VisioFile
def get(self, request, *args, **kwargs):
        
    filename = 'test.vsdx'
    response = HttpResponse(VisioFile(filename), content_type="application/vnd.visio", status=status.HTTP_200_OK)
    response["Content-Disposition"] = f"attachment; filename=temp.vsdx"

    return response

Back to Top