from fastapi import FastAPI
from fastapi.params import Body
app = FastAPI()
@app.post("/createposts")
def create_posts(payload: dict = Body(...)):
print(payload)
return {"new_post" : f"title {payload["title"]} content: {payload["content"]}"}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 Fastapi 创建 API,但每次运行代码时都会收到与 return 语句相关的错误: SyntaxError: f-string: unmatched '['
谢谢你!
请更换
return {"new_post" : f"title {payload["title"]} content: {payload["content"]}"}
到
return {"new_post" : f"title {payload['title']} content: {payload['content']}"}
"里面不能有引号f"..."
该错误表明,在第一个字符串之后,[字符串停止并断开。
| 归档时间: |
|
| 查看次数: |
3731 次 |
| 最近记录: |