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

后端 未结 3 1268
[愿得一人]
[愿得一人] 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

    uWSGI doesn't load your app as __main__, so it never will find the app (since that only gets loaded when the app is run as name __main__). Thus, you need to import it outside of the if __name__ == "__main__": block.

    Really simple change:

    from app import app as application  # for example, should be app
    
    if __name__ == "__main__":
        application.run()
    

    Now you can run the app directly with python run.py or run it through uWSGI the way you have it.

    NOTE: if you set --callable myapp, you'd need to change it from as application to myapp (by default uwsgi expects application

提交回复
热议问题