简体   繁体   English

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

[英]How to use flask-caching in my structure of project

My code structure.我的代码结构。 I tried but kept getting error cannot import name 'caching'.我试过,但不断收到错误无法导入名称“缓存”。 I guess my method isn't correct as caching will not have app initiation when I import caching in external file.我想我的方法不正确,因为当我在外部文件中导入缓存时,缓存不会启动应用程序。

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 v1.py

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

It is a simple factory app setup这是一个简单的工厂应用程序设置

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM