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:04
jinja templates, which we already completely and set up and we're working with for the
0:09
HTML side of our flask website.
0:11
We're able to leverage that for generating consistent and beautiful email.
0:16
And in order to do so,
0:17
we had to have a template file with potentially,
0:20
uh, common layout wrapper. But we don't deal with that here.
0:23
That's all the template engine level.
0:25
We're going to have this HTML template file.
0:27
We want to pass data over to it just like we would for a Web page
0:30
with Jinja. So we wrote this super simple function here,
0:34
and it's just gonna basically set up a one time jinja environment.
0:37
In order to do that, we've got to figure out where the template folder is
0:41
We use the path lib, path object to do so.
0:44
I mean, we use jinja2 we said,
0:46
create a file system loader from that location,
0:48
create an environment from that loader,
0:50
and then use that loader to load up a template and then finally render the template
0:55
given the data really quite easy and very useful,
0:58
which can be reused all over the place and you can actually render stuff that's not
1:02
just HTML basically any text file.
1:05
If you've got RSS you want to generate,
1:07
you can use that for XML could even just generate plain text out of this kind
1:11
of thing, really, really useful and flexible inside your application in many ways.