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)
Brige the gap between Tutorial hell and Industry. We want to bring in the culture of Clean Code, Test Driven Development.
We know, we might make it hard for you but definitely worth the efforts.
© Copyright 2022-23 Team FastAPITutorial