You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Uvicorn运行Dash应用报错:TypeError: 'Dash' object is not callable

解决Dash应用用Uvicorn启动时出现"TypeError: 'Dash' object is not callable"的问题

你遇到的问题核心是:Uvicorn启动时需要一个符合ASGI/WSGI规范的可调用服务器对象,但直接传入Dash实例并不满足这个要求——Dash内部封装了Flask(或FastAPI)的服务器实例,你需要暴露这个底层的server属性给Uvicorn。

解决方案步骤

  • 修改代码,导出Dash应用的server属性
  • 调整Uvicorn启动命令,指向这个server对象

修改后的完整代码

from dash import Dash, html

dash_app = Dash(__name__)
dash_app.layout = html.Div(id='main-layout', children=["hello"])

# 导出Uvicorn可直接调用的底层server对象
server = dash_app.server

正确的Uvicorn启动命令

uvicorn uvicorn_test.__main__:server

执行以上命令启动后,访问localhost对应端口就能正常显示"hello"页面了。

内容的提问来源于stack exchange,提问作者Nathan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 06:00:17