Skip to content

Commit 97efcd6

Browse files
authored
Merge pull request #67 from AmSach/fix/template-response-cache-key
fix: use modern Starlette TemplateResponse signature in sample app
2 parents 1905ace + 6bbc05e commit 97efcd6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

examples/sample_app/configurable_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ async def get_reference_audios():
5353

5454
@app.get("/", response_class=HTMLResponse)
5555
async def read_root(request: Request):
56-
return templates.TemplateResponse("index.html", {"request": request})
56+
# Use the modern Starlette TemplateResponse(request, name, context) signature.
57+
# The old "TemplateResponse(name, context)" form puts ``request`` into the
58+
# context dict, and jinja2 tries to hash the cache key as ``(name, context)``
59+
# which fails because ``request`` is an unhashable mapping. See issue #62.
60+
return templates.TemplateResponse(request, "index.html", {})
5761

5862

5963
if __name__ == "__main__":

0 commit comments

Comments
 (0)