Modern APIs with FastAPI and Python Transcripts
Chapter: Course conclusion and review
Lecture: Review: Rendering templates
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
FastAPI is an API first framework, meaning if you just write basic view methods and return stuff,
0:07
it's going to treat it as JSON data and kind of talk to in styles that typically API's and think consuming API's would expect.
0:15
But that doesn't mean you can't actually do basic Web stuff, HTML stuff, there. So Flask supports Jinja templates, and that is also built into
0:25
FastAPI. So we could come over here and write our index.html, which derives or extends from layout.html. In order to use it,
0:33
all we have to do is come over here, create the templates object and say where the templates come from.
0:39
Remember, this means we have to pip install Jinja in order to do so. And then during our function, we want to return HTML,
0:46
we just say templates, template response, give it the name of the template and then some kind of dictionary with all the values being passed over.
0:53
You have to have request in anything else you program against, But request is a minimum. And that's it, now you have a web framework on top of FastAPI.