[英]Python Dash server with waitress
I have a dashboard application written in Dash framework.我有一个用 Dash 框架编写的仪表板应用程序。 It also has a few Restful API's written using flask.它还有一些使用 flask 编写的 Restful API。 I am adding flask app to Dash server, as我将 flask 应用程序添加到 Dash 服务器,如
import dash
import flask
import dash_bootstrap_components as dbc
flask_server = flask.Flask(__name__)
app = dash.Dash(__name__,server=flask_server, external_stylesheets=[dbc.themes.BOOTSTRAP])
And am running the server as并将服务器运行为
from dashboard import app
from waitress import serve
if __name__ == "__main__":
app.title = 'Litmus'
app.run_server(debug=False)
# serve(app,host="0.0.0.0",port=8050)
The above code works fine when I am using app.run_server(debug=False)
but it throws excetion when I use waitress to run the server.上面的代码在我使用app.run_server(debug=False)
时工作正常,但是当我使用 waitress 运行服务器时它会抛出异常。 When I use following lines当我使用以下几行
#app.run_server(debug=False)
serve(app,host="0.0.0.0",port=8050)
I get following error我收到以下错误
ERROR:waitress:Exception while serving /
Traceback (most recent call last):
File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\channel.py", line 397, in service
task.service()
File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 168, in service
self.execute()
File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 434, in execute
app_iter = self.channel.server.application(environ, start_response)
TypeError: 'Dash' object is not callable
ERROR:waitress:Exception while serving /favicon.ico
Traceback (most recent call last):
File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\channel.py", line 397, in service
task.service()
File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 168, in service
self.execute()
File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 434, in execute
app_iter = self.channel.server.application(environ, start_response)
TypeError: 'Dash' object is not callable
It's not working because you're passing the Dash app instead of the Flask app to serve
.它不起作用,因为您传递的是 Dash 应用程序而不是 Flask 应用程序来serve
。
So instead of this:所以代替这个:
serve(app,host="0.0.0.0",port=8050)
pass the Flask app instance like this:像这样传递 Flask 应用程序实例:
serve(app.server, host="0.0.0.0", port=8050)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.