Before FastAPI 0.108.0), name was the first positional parameter, and the request had to be manually jammed inside the context dictionary. In newer FastAPI/Starlette versions, TemplateResponse enforces request as the first argument, and request, name, and context should be passed explicitly as keyword arguments (ref: https://fastapi.tiangolo.com/advanced/templates/#using-jinja2templates), such as:
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.get("/items/{id}")
async def read_item(request: Request, id: str):
return templates.TemplateResponse(
request=request,
name="item.html",
context={"id": id}
)
Running current code such as templates.TemplateResponse("index.html", {"request": request}) will trigger type error TypeError: unhashable type: 'dict' causing 500 internal server error.
Action items:
- Update TemplateResponse to use the newer version signature and syntax
- Run unit tests
- Test Resolver with a development instance using uvicorn
Before FastAPI 0.108.0), name was the first positional parameter, and the request had to be manually jammed inside the context dictionary. In newer FastAPI/Starlette versions, TemplateResponse enforces request as the first argument, and request, name, and context should be passed explicitly as keyword arguments (ref: https://fastapi.tiangolo.com/advanced/templates/#using-jinja2templates), such as:
Running current code such as
templates.TemplateResponse("index.html", {"request": request})will trigger type errorTypeError: unhashable type: 'dict'causing 500 internal server error.Action items: