我想从 Jinja2 模板中调用 FastAPI 路由,并将路径和查询数据(参数)传递给该路由。我在 Jinja2 模板中尝试过如下所示:
{{ url_for('function1', uustr=data.uustr, interval=1) }}
Run Code Online (Sandbox Code Playgroud)
这是我想要调用的 FastAPI 路由(为了演示目的,语法已被简化):
@app.get("/updates/data/{uustr}",response_class=HTMLResponse)
async def function1(request: Request, uustr:str, interval:int):
return"""
<html>
<head>
<title>{{ uustr }}</title>
</head>
<body>
<h1>{{ interval }}</h1>
</body>
</html>
"""
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
raise ValueError('context must include a "request" key')
ValueError: context must include a "request" key
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?