RuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret

It has nothing to do with cache. In order to use sessions you have to set a secret key: http://flask.pocoo.org/docs/1.0/quickstart/#sessions

Add the following (obviously don't use my example and change the secret key) after initialising your app:

app = Flask(__name__)

# Set the secret key to some random bytes. Keep this really secret!
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'

You can generate secrets on the fly:

import secrets

secret = secrets.token_urlsafe(32)

app.secret_key = secret

Tags:

Python

Flask