Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Beautiful confirmation emails
Lecture: Generate the invoice HTML

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We're starting to put together some really neat building blocks here with our email, Jinja language thing and so on. In order to do our next step,
0:10 we have to build a pdf invoice, and I have a really cool library to show you how to do that.
0:14 And the easiest way for us to do so is to give it HTML as a string and say, Turn that HTML into a pdf.
0:22 Do we have a cool way to generate dynamic HTML just as text? Mm hmm. We sure do build HTML.
0:30 So what about this invoice_HTML= build_HTML('email/invoice.html') and the template will be email/invoice.html and the data will be the same,
0:42 I think should be sufficient. How cool is that? And then we're going to turn this HTML into a pdf with a couple lines of
0:50 Python. The first thing we got to do is create this right here, So over here again, we're using our shared layout for all of our emails were
1:01 sending, But this is like a formal invoice, so we're not going to inherit its design.
1:06 I said I'm going to just drop in some text as I have been doing and let's go up and look. Now we've got our invoice as our title.
1:13 I'm not even sure that's really used in the PDF, but the rest of this is Here's our body. It'll say. Here's official company name.
1:21 Here is a table of the things you bought. It's built to so and so on such and such date. And here's a description of what you bought and so on.
1:29 Really cool. Okay, so can we generate this? Let's go. Look, we've already written all the code to do it.
1:35 Probably let's just print it out and see what we get. Run it and hit it with postman again. All right, let's see what we got.
1:46 It worked. And check this out. Here is our fancy HTML of our invoice. Now, that's just like before,
1:55 But the trick is we're going to turn this into a pdf. That will be really nice in just a second.


Talk Python's Mastodon Michael Kennedy's Mastodon