I use gunicorn
to work with flask application. Here's my project structure.
flask-application
|-- non_web/
| |--...
|
|-- web/
|--app/
| |--api/
| | |--...
| |--...
| |--__init__.py # Here's def create_app()
|
|--config.py # Here's config of flask application
|--config_gunicorn.py # Here's config of gunicorn
|--run.py
When I execute command line [XXX@XXXX flask-application]# gunicorn -c web/config_gunicorn.py web.run:app
, here raised a error ImportError: cannot import name 'XXX' from 'web.run' (/root/flask-application/web/run.py)
Here's run.py
```python
from web.app import create_app
app, whitelist = create_app(conf_type='default')
if __name__ == '__main__':
app.run(host=app.config['HOST'], port=app.config['PORT'])
```
Here's __init__.py
```python
from flask import Flask
import redis
from ..config import config
def create_app(conf_type):
app = Flask(__name__)
app.config.from_object(obj=config[conf_type])
config[conf_type].init_app(app=app)
from .api import api as api_blueprint
app.register_blueprint(blueprint=api_blueprint,
url_prefix='/api')
whitelist = redis.StrictRedis(host=config[conf_type].REDIS_HOST,
port=config[conf_type].REDIS_PORT,
db=config[conf_type].REDIS_DB_WHITELIST,
decode_responses=True)
return app, whitelist
```
And config_gunicorn.py
follows this: github.com/benoitc/gunicorn/blob/master/examples/example_config.py
It goes well when launching run.py
without gunicorn
on windows. Is there any help ? Thanks.