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

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In our previous chapter, you saw we built a simple FastAPI,
0:04 API more or less, returned JSON.
0:06 And our goal now is actually to exchange HTML.
0:10 We may also want to build APIs
0:12 with FastAPI, I mean,
0:13 that's one of its main purposes.
0:15 But if we're gonna have web pages that talk to browsers,
0:18 we need to return HTML. Now, the last thing we want to do is write
0:22 static HTML in strings in Python and then return it.
0:26 No, no, no. We want to use one of these dynamic templating
0:28 languages like Jinja or Chameleon or even similar to what you have in the Django templates,
0:34 where we write HTML and we put a little bit of scripting in the HTML
0:39 and the scripting varies by templating language.
0:41 But the general idea is we put some scripting or some conditional stuff into our HTML. In
0:48 FastAPI we're going to create a dictionary and hand that off to this
0:52 template and say: render all these items and here's the pieces of data that you're
0:56 going to need to work with.
0:57 So that's what we're gonna do in this chapter.
0:59 We're going to start really simple and just see how to return
1:01 HTML. Then we're gonna leverage,
1:03 a cool library that allows us to basically do what I just described:
1:07 create a dictionary and just hand it off in the simplest possible way to under one of this underlying templating languages