Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)

后端 未结 3 1311
[愿得一人]
[愿得一人] 2020-11-29 23:57

I get the below error when I try and start Flask using uWSGI. Here is how I start:

>  # cd ..
>     root@localhost:# uwsgi --socket 127.0.0.1:6000 --fi         


        
3条回答
  •  时光说笑
    2020-11-30 00:19

    The uWSGI error unable to load app 0 (mountpoint='') (callable not found or import error) occured for me if I left out the last two lines of the following minimal working example for Flask application

    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    def hello():
        return "Hello world!"
    
    if __name__ == "__main__":
        app.run()
    else:
        application = app
    

    I am aware that this already implicitly said within the comments to another answer, but it still took me a while to figure that out, so I hope to save others' time.

    In the case of a pure Python Dash application, I can offer the following minimal viable code snippet:

    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    app = dash.Dash()
    app.layout = html.Div( html.H1(children="Hello World") )
    
    application = app.server
    
    if __name__ == "__main__":
        app.run_server(debug=True)
    

    Again, the application = app.server is the essential part here.

提交回复
热议问题