Dynamically generate PDF and email it using django

Posted by Shane on Stack Overflow See other posts from Stack Overflow or by Shane
Published on 2010-05-07T15:24:04Z Indexed on 2010/05/07 15:28 UTC
Read the original article Hit count: 551

Filed under:
|
|

I have a django app that dynamically generates a PDF (using reportlab + pypdf) from user input on an HTML form, and returns the HTTP response with an application/pdf MIMEType.

I want to have the option between doing the above, or emailing the generated pdf, but I cannot figure out how to use the EmailMessage class's attach(filename=None, content=None, mimetype=None) method. The documentation doesn't give much of a description of what kind of object content is supposed to be. I've tried a file object and the above application/pdf HTTP response.

I currently have a workaround where my view saves a pdf to disk, and then I attach the resulting file to an outgoing email using the attach_file() method. This seems wrong to me, and I'm pretty sure there is a better way.

© Stack Overflow or respective owner

Related posts about django

Related posts about email