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"]}"}
I’m trying to create an API with Fastapi, but every time I run the code I get this error related to the return statement: SyntaxError: f-string: unmatched ‘[‘
Thank you!
>Solution :
Pleas change
return {"new_post" : f"title {payload["title"]} content: {payload["content"]}"}
to
return {"new_post" : f"title {payload['title']} content: {payload['content']}"}
You can’t have " quotes inside f"..."
The error says that after the first [ the string stops and breaks.