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,
0:04 Jinja language thing and so on.
0:07 In order to do our next step,
0:09 we have to build a pdf invoice,
0:11 and I have a really cool library to show you how to do that.
0:13 And the easiest way for us to do so is to give it html as a
0:17 string and say, Turn that html into a pdf.
0:21 Do we have a cool way to generate dynamic HTML just as text?
0:25 Mm hmm. We sure do build html.
0:29 So what about this invoice_html= build_html('email/invoice.html') and the template will be
0:36 email/invoice.html and the data will be the same,
0:41 I think should be sufficient. How cool is that?
0:45 And then we're going to turn this html into a pdf with a couple lines of
0:49 python. The first thing we got to do is create this right here,
0:53 So over here again, we're using our shared layout for all of our emails were
1:00 sending, But this is like a formal invoice,
1:02 so we're not going to inherit its design.
1:05 I said I'm going to just drop in some text as I have been doing and
1:08 let's go up and look. Now we've got our invoice as our title.
1:12 I'm not even sure that's really used in the PDF,
1:15 but the rest of this is Here's our body.
1:17 It'll say. Here's official company name.
1:20 Here is a table of the things you bought.
1:22 It's built to so and so on such and such date.
1:24 And here's a description of what you bought and so on.
1:28 Really cool. Okay, so can we generate this?
1:31 Let's go. Look, we've already written all the code to do it.
1:34 Probably let's just print it out and see what we get.
1:39 Run it and hit it with postman again.
1:44 All right, let's see what we got.
1:45 It worked. And check this out.
1:48 Here is our fancy html of our invoice.
1:53 Now, that's just like before,
1:54 But the trick is we're going to turn this into a pdf. That will be really nice in just a second.