是否有可能将一个函数传递给一个路由,然后调用它?我试过这样做,但没有用:
app = FastAPI()
class GetFunction(BaseModel):
function: Callable
def hello():
return print("Hello world")
@app.post("/datalore")
def datalore(function: GetFunction):
function()发布于 2022-11-09 18:26:35
最简单的方法就是得到你想要调用的函数的字典。
app = FastAPI()
def hello():
print("Hello!")
@app.post("/datalore")
def datalore(function: str):
func_dict = {"hello": hello}
func_to_call = func_dict[function]
return func_to_call()https://stackoverflow.com/questions/74379522
复制相似问题