Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Beautiful confirmation emails
Lecture: Concept: Jinja to HTML email content
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
One of the really neat things we did here was leverage the ability of having our
0:05
jinja templates, which we already completely and set up and we're working with for the HTML side of our flask website.
0:12
We're able to leverage that for generating consistent and beautiful email. And in order to do so, we had to have a template file with potentially,
0:21
common layout wrapper. But we don't deal with that here. That's all the template engine level. We're going to have this HTML template file.
0:28
We want to pass data over to it just like we would for a Web page with Jinja. So we wrote this super simple function here,
0:35
and it's just gonna basically set up a one time jinja environment. In order to do that, we've got to figure out where the template folder is
0:42
We use the path lib, path object to do so. I mean, we use jinja2 we said, create a file system loader from that location,
0:49
create an environment from that loader, and then use that loader to load up a template and then finally render the template
0:56
given the data really quite easy and very useful, which can be reused all over the place and you can actually render stuff that's not
1:03
just HTML basically any text file. If you've got RSS you want to generate,
1:08
you can use that for XML could even just generate plain text out of this kind
1:12
of thing, really, really useful and flexible inside your application in many ways.