From my past experience with the MVC pattern, we can access request
in our templates via request.something.this
. Continuing your videos, it seems like I don't see you ever accessing the request
object as you do with job
in the later lectures.
With a quick search, "... when using templates.TemplateResponse
in a FastAPI web application, it is not mandatory to pass the request
parameter explicitly."
Why are we passing the request
object if we are not using it?
Yup, I had given it a try,
When I don't pass the context dictionary, I used to get an error saying: TemplateResponse() missing 1 required positional argument: 'context'
If we don't pass the request key in the context then TemplateResponse complained that a key named request is compulsory.
This is because starlette injects the properties of the request into context. For instance, the request can have an url,path, scheme(http/https). These are auto-injected to context. (Reference)
My priority is to help build a production-ready application using FastAPI
I prioritize quality over simplicity. Our challenging approach ensures you're prepared for real-world development.
© Copyright 2022-2025 Team FastAPITutorial. All rights reserved.