如何最好地使用Django和ReportLab生成PDF并将其附加到电子邮件消息?
我正在使用SimpleDocTemplate,并可以将生成的PDF附加到我的HttpResponse中 - 这很好,但我无法找到如何将同样的附件添加到电子邮件的确切方法:
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=invoice.pdf'
doc = SimpleDocTemplate(response, pagesize=letter)
Document = []
我想通过将表格添加到文档中来制作PDF文件...
doc.build(Document)
email = EmailMessage('Hello', 'Body', 'from@from.com', ['to@to.com'])
email.attach('invoice.pdf', ???, 'application/pdf')
email.send()
我不确定如何将我的pdf文档转换为blob,以便于email.attach接受并通过email.send发送。 有什么想法吗?