python f-strings with path parameters within fastapi path

Question:

I’m wondering if you can use f strings within a path in fastapi. For example, I want to do the following:

common_path = '/{user}/{item_id}'

@app.get(f'{common_path}/testing')

would this work?

Answers:

Yes it’s work as intended!

from fastapi import FastAPI

app = FastAPI()
common_path = '/{user}/{item_id}'
@app.get(f'{common_path}/testing')
def read_commom_path(user: int, item_id: int):
    return {"user": user, "item_id": item_id}

And running uvicorn as uvicorn fastApiTest:app --reload --host localhost --port 1999

And below is the result from testing using Postman
Postman