与 中一样ExpressJS,app.get("/*")适用于所有路线。
我的代码 -
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get('/*')
def user_lost():
return "Sorry You Are Lost !"
Run Code Online (Sandbox Code Playgroud)
我尝试过,但网页结果显示{"detail":"Not Found"}
How can I do the same in FastApi?
您可以使用/{full_path}捕获一条路径中的所有路由(请参阅文档)。
@app.route("/{full_path:path}")
async def capture_routes(request: Request, full_path: str):
...
Run Code Online (Sandbox Code Playgroud)