在Fastapi中安装多个子应用
我有两个FastApi子应用程序,一个叫做api_app
,另一个admin_app
。我想将这两个应用程序安装到我的主要应用程序中:
app.mount('/', api_app, name='api')
app.mount('/', admin_app, name='admin_api')
当我尝试从应用程序admin_app
访问端点时,我找到找不到
响应。
我知道可以使用apirouter
来解决此问题,但是在我的情况下,我需要使用fastapi
应用程序,因为我需要将middlwares添加到api_app
。
我认为解决方案是覆盖第一个应用程序的404异常处理程序
,但我不知道如何将请求传递给下一个应用程序。
I have two fastapi sub apps, one called api_app
and the other admin_app
. I want to mount those 2 apps to my main app like that:
app.mount('/', api_app, name='api')
app.mount('/', admin_app, name='admin_api')
When I try to access an endpoint from the app admin_app
I get Not Found
response.
I know this can be solved using APIRouter
but in my case I need to use FastAPI
app because I need to add middlwares to api_app
.
I think the solution is to override the 404 exception handler
of the first app, but I don't know how to pass the request to the next app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将路径名添加到您的已安装应用程序中,例如:
try to add path name into your mounted app like:
我相信您的问题在于在同一路径上分配两个应用程序,root(“/”)。
如@ashkan所述,如果您提供了与第一个应用程序不同的路径,则应解决此问题。
I believe your issue lies in assigning two apps on the same path, root (“/“).
As @ashkan mentioned if you provide any path different from the first app that should resolve this.