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, API more or less, returned JSON. And our goal now is actually to exchange HTML.
0:11
We may also want to build APIs with FastAPI, I mean, that's one of its main purposes. But if we're gonna have web pages that talk to browsers,
0:19
we need to return HTML. Now, the last thing we want to do is write static HTML in strings in Python and then return it.
0:27
No, no, no. We want to use one of these dynamic templating languages like Jinja or Chameleon or even similar to what you have in the Django templates,
0:35
where we write HTML and we put a little bit of scripting in the HTML and the scripting varies by templating language.
0:42
But the general idea is we put some scripting or some conditional stuff into our HTML. In
0:49
FastAPI we're going to create a dictionary and hand that off to this template and say: render all these items and here's the pieces of data that you're
0:57
going to need to work with. So that's what we're gonna do in this chapter. We're going to start really simple and just see how to return
1:02
HTML. Then we're gonna leverage, a cool library that allows us to basically do what I just described:
1:08
create a dictionary and just hand it off in the simplest possible way to under one of this underlying templating languages