I've started using a separate virtualenv for my project with virtualenvwrapper. I also loaded my variables into the /home/leapfrog/.virtualenvs/myenv/bin/postactivate and restarted my app. Everything seems fine and my app works just as before. I can 'workon' my environment and echo the environment variables. In my configurations I can also print out the variables like so
import os
class Config(object):
DEBUG = False
TESTING = False
SECRET_KEY = 'hard coded secret key'
print os.getenv('SECRET_KEY')
class ProductionConfig(Config):
DATABASE_URI = 'mysql://user@localhost/foo'
and it will print out the appropriate SECRET_KEY for my virtualenv (not the hard coded SECRET_KEY).
>>> virtualenv secret key
. However when I want to actually assign the SECRET_KEY in my virtualenv to my configuration settings like so:
import os
class Config(object):
DEBUG = False
TESTING = False
SECRET_KEY = os.getenv('SECRET_KEY')
class ProductionConfig(Config):
DATABASE_URI = 'mysql://user@localhost/foo'
The SECRET_KEY will fail to be loaded into the app configuration and I'll receive this error in my stack trace:
RuntimeError: the session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
So, if I can print out the variables in my virtualenv in my console as well as my configuration file, but can't assign them what exactly am I getting wrong?