Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Course conclusion
Lecture: Jinja2 templates and dynamic HTML

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Unless you're building, purely, some sort of API endpoint you're going to want to have dynamic HTML and even in those endpoint stories
0:09 you probably want to have some landing page that say Here's our API and go over this GitHub repo for the documentation, or something like that.
0:17 So let's talk about Jinja2, right. That's the default dynamic HTML language for Flask. And it works like this.
0:24 It's mostly HTML, but with these curly-brace percent blocks where we sprinkle in Python, and these double-handlebar
0:33 double curly-brace things where we stringify things we take the value, some expression and we print out the string value right there.
0:42 For example, we're looping over the packages and we're going to replicate this div block, three times
0:47 for three packages, or five times for five packages. However many we pass in, we want to have one of these blocks
0:52 for each one of those, so we just have for p in packages. Notice there's no colon, that's handled by the endfor down there.
1:01 If we want to have just string values as I said double handlebars, and some kind of expression. You can call Python code here, and methods and whatnot
1:09 but ultimately the return value is going to be just printed out as a string. We also saw that we have if statements.
1:15 So we want to conditionally show the summary only if there is a summary, we'll do it this way. Of course, all those blocks have to be closed
1:23 with an endif, or an endfor, and so on. If we run this, how's it going to look? Let's say we pass three packages request, Boto and SQLAlchemy.
1:31 It'll look something like this. The style, the web design, not overwhelming, is it? But, you know, this is just getting started, right?
1:38 This is just the barebones Let's show the data in HTML. This is how we do it with Jinja2.

Talk Python's Mastodon Michael Kennedy's Mastodon