如何在我的项目结构中使用烧瓶缓存

How to use flask-caching in my structure of project

我的代码结构。我试过了,但一直收到错误无法导入名称 'caching'。我想我的方法不正确,因为当我在外部文件中导入缓存时,缓存不会启动应用程序。

xyz
  -app.py
  -run.py
  -urls
    -v2.py
  -resource
    -views.py
  -external.py

run.py

from app import create_app
if __name__ == "__main__":
    career_app = create_app()
    career_app.run(host=HOST,
                   port=PORT,
                   debug=True)

app.py

from flask import Flask
from flask_caching import Cache
caching = Cache(config={'CACHE_TYPE': 'simple'})
def create_app():
    """Create web app."""
    app = Flask(__name__)
    configure_app(app)
    caching.init_app(app)
    setup_blueprints(app)
    return app

external.py

from app import caching

v1.py

v2_api.add_resource(UserConfigView, '/user/config',
                    endpoint='user_config_view')

这是一个简单的工厂应用设置

ext.py

from flask_caching import Cache
cache = Cache()

app.py

def create_app():
    app = Flask(__name__)
    register_extensions(app)
    ...

def register_extensions(app):
    cache.init_app(app, config=settings.params.CACHE_CONFIG)