How do I run a flask app in gunicorn if I used the application factory pattern?

后端 未结 2 909
攒了一身酷
攒了一身酷 2020-12-13 17:25

I wrote a flask app using the application factory pattern. That means it doesn\'t create an app instance automatically when you import it. You have to call create_app for

2条回答
  •  死守一世寂寞
    2020-12-13 18:02

    You need to create_app() with specific factory config in run.py. See the code below:

    from your_app import create_app
    
    if __name__ == "__main__":
        app = create_app(os.getenv('FLASK_CONFIG') or 'dev')
        app.run()
    

    And then, you could run command gunicorn -w 4 -b 0.0.0.0:5000 run:create_app('dev') to run the application.

提交回复
热议问题