Full Web Apps with FastAPI Transcripts
Chapter: Dynamic HTML templates
Lecture: Template languages options

Login or purchase this course to watch this video and the rest of the course contents.
0:00 With Python, we have a choice of different template languages. So what I'd like to do in this section is talk about three of the main
0:08 possible choices that you might choose for this dynamic HTML templating that we're gonna do
0:13 and see the trade offs, and then we have to pick one and go with it for the course. So we're going to do that,
0:18 and I'll give you the motivation for doing so. But let's go through three popular ones. If you've ever done Flask, you've done Jinja.
0:25 So, Jinja is really the one templating language that is deeply supported by Flask.
0:30 There are many other frameworks that use Jinja as well. A lot of different, maybe smaller web frameworks that are not quite as popular,
0:37 that also happen to leverage Jinja, so Jinja very well may be the most popular,
0:41 most well known choice. Mako is another template language and looks quite similar to Jinja. I think I actually like
0:49 Mako a little bit better, you'll see that there's a little bit less: open, close, open, close all of these things
0:54 you have to keep writing; and it's, here's a template line and then you just write some Python. That's pretty nice.
1:01 And then we're also going to talk about Chameleon. Chameleon is unique because it doesn't leverage directly writing Python as much,
1:08 but it uses more of an attribute driven way of working with the HTML so you might pass some date over. There might be an attribute that says:
1:17 if this condition is true, show or hide this element that has the attribute,
1:21 whereas Jinja and Mako would actually have an if statement directly in their HTML,
1:26 so there's drawbacks and benefits to each one of these as we will see.


Talk Python's Mastodon Michael Kennedy's Mastodon