python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

Cannot open the pptx neither in Keynotes and Powerpoint.

Open 9Shuck opened this issue 2 years ago • 2 comments

Hello, I'm just trying to get an example of a pptx to start adding things. But I cannot even open the pptx I got from my code.

This is the code, so simple. As I don't receive any extra info or errors don't know what is going bad.

        prs = Presentation()
        
        title_slide_layout = prs.slide_layouts[0]
        slide = prs.slides.add_slide(title_slide_layout)
        title = slide.shapes.title
        subtitle = slide.placeholders[1]

        title.text = "Hello, World!"
        subtitle.text = "python-pptx was here!"

        prs.save('test.pptx')

        response = HttpResponse(prs, headers={
            'Content-Type': 'application/vnd.ms-powerpoint',
            'Content-Disposition': 'attachment; filename="test.pptx"',
        })

        return response

Thank you so much.

9Shuck avatar Feb 23 '23 16:02 9Shuck

What are your import statements?

MartinPacker avatar Feb 23 '23 16:02 MartinPacker

Sorry for the delay, my imports are (have some Django imports on views file):

from pptx import Presentation
from ...views import viewsets, APIView, IsAuthenticated, action,\
    HttpResponse

I'm not getting any error 😅

9Shuck avatar Mar 01 '23 08:03 9Shuck