Reputation: 589
I am using application factory pattern in which I have initialized my cache
from xyz.caching import cache # this is the cache object
def create_app():
app = Flask(__name__)
cache.init_app(app)
# other relevant variables.
return app
My caching.py
from flask_caching import Cache
cache = Cache(config={....})
When I import this in any file xyz.caching import cache, this works totally fine. However, in my application I have a entry point script, run.py
run.py
from xyz.caching import cache
def run_this():
cache.get('XXX')
if __name__ == "__main__":
run_this()
After running python run.py, I get the following error
'AttributeError: 'Cache' object has no attribute 'app''
Pls. guide me what is wrong in this, why I am getting this error and what is the way to solve this ?
Upvotes: 3
Views: 4962
Reputation: 118
I got this message because I forgot to initialize the app
cache.init_app(app)
I would try to debug if this method call is reached before cache.get('XXX') is called.
Upvotes: 2