nickpick nickpick - 6 months ago 4x
Python Question

Flask doesn't get secret_key config from config object

I have a config class that has the config for my Flask app. Most of the config options are picked up, but the

remains unset, and so using the session raises an error. Why isn't the config fully imported?

app = Flask(__name__)

class BaseConfig(object):
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'
secret_key = '122332'

When I access a view that uses the session, I get this error:

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


Config keys are all uppercase, to distinguish between config and other attributes on whatever object is being scanned. The key secret_key is lower case, so it's not picked up.

SECRET_KEY = 'stack overflow'