HTMX + Flask: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: HTML template partials
Lecture: The jinja-partials package

Login or purchase this course to watch this video and the rest of the course contents.
0:00 When we're creating web applications, there's often times we need to duplicate some part of our
0:07 HTML. Here's an example from a project I'm about to tell you about. You can see we've got a video,
0:14 we've got a subtitle, and we have the number of views, and we're going to use
0:17 that on the homepage, and we're also going to use that in this listing where we can see more of them. They should look kind of familiar,
0:23 huh? Well that is exactly the same thing. Yes, it's in a different section, and it probably has a different overall CSS selector
0:32 applied to it, but the HTML is identical. And so, why should we write that and maintain it in multiple places?
0:39 We've already seen that in our application. Remember the click to add video button? It has to appear in two places.
0:45 But I really wanna emphasize that while this is not specifically about htmx, it really applies to all web applications.
0:53 They would benefit from having more organization. It especially applies to using htmx with any of the Python web frameworks be that
1:02 Flask, Pyramid, Django or some other one like FastAPI. So this ability to reuse like a function parts of our HTML in different places is
1:15 really critical. We haven't seen a complicated example of it yet, but if we kept going without taking a pause and adopting this package,
1:24 we'd be in big trouble. Speaking of the package, here we go, Jinja Partials.
1:29 So this package Jinja Partials, which I created specifically for this course, as well as I
1:34 just realized this problem is not being solved in Jinja or Chameleon or Django templates. All the places, that really should be solved better.
1:43 So I created this package specifically for Jinja. Notice right under the title there, it says there's also a Pyramid/Chameleon version.
1:50 So if you're using Chameleon, you're not left out. We're going to use this Jinja partial package to make our code much cleaner and have
1:59 it defined one time, not in multiple places, in our Flask plus htmx web app.


Talk Python's Mastodon Michael Kennedy's Mastodon