python - Get xhtml2pdf data in django as variable -


I generated by some of the PDF files in your Dijengo app:

  context = context ({ 'Data': data_object, 'MEDIA_ROOT': settings.MEDIA_ROOT}) html = template.render (context) result = string IO.StringIO () pdf = pisa.pisaDocument (StringIO.StringIO (html.encode ( 'UTF- 8 ')), results) if not pdf.err: response = HttpResponse (result.getvalue ()) response [' content-type '] =' application / pdf 'response [' content-conflict '] =' attachment; File name = "% s.pdf" '% (title) return response  

And it works great, however, when the user wants to download the PDF file, please email me this message Need to engage in That is why I will need to get the content of this PDF. I am not getting anything in XHTMLPDF docs. Can you help me solve it?

You can already here:

  HttpResponse ( result.getvalue ()) # result.getvalue () lets you as a PDF file contents to a string  

... so you can take it and your

Example:

  Import email from email. Mime.multipart Import MIMEMultipart email.mime the Text Import import MIMEText email.utils formatdate context = Context ({ 'data': data_object, 'MEDIA_ROOT': settings.MEDIA_ROOT}) html = template.render (context) result = StringIO.StringIO () pdf = pisa.pisaDocument (StringIO.StringIO (html.encode ('UTF-8', results) if not pdf.err: msg = MIMEMultipart (From = 'from@example.com', To = 'To@example.com', date = Formatdate (localtime = true), subject = "this is your pdf!") Msg.attach (MIMEText (result.getvalue ()) smtp = smtplib.SMTP ('smtp.google Mail.com ') # for example smtp.sendmail (' from@example.com ', [' to@example.com '], msg.as_string ()) smtp.close ()  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -