Flask_caching in DASH App - AttributeError: 'Dash' object has no attribute 'jinja_env'

Helllo,
I am trying to implement flask_caching in my Dash App. I get ‘Dash’ object has no attribute ‘jinja_env’

from flask_caching import Cache
from dash import Dash

mycache = Cache(
    config={
        # settings for cache
        "CACHE_TYPE": "FileSystemCache",
        "CACHE_DIR": "./mycache",
        "CACHE_DEFAULT_TIMEOUT": 3600,
    }
)

app = Dash(
    __name__,
    suppress_callback_exceptions=True,
)
app.title = 'SAMPLE APP'
mycache.init_app(app)

Traceback (most recent call last):
File “/home/dsp/workspace/code/project/app_cache.py”, line 18, in
mycache.init_app(app)
File “/home/dsp/workspace/code/project/venv/lib/python3.8/site-packages/flask_caching/init.py”, line 138, in init_app
setattr(app.jinja_env, JINJA_CACHE_ATTR_NAME, self)
AttributeError: ‘Dash’ object has no attribute ‘jinja_env’

Issue resolved after I made the following change.

    mycache.init_app(app.server)
1 Like