I'm going through an online tutorial for building a Python/Flask app. Before I installed Postgres and messed with my database I could launch my app from command line no problem. Now, everytime I restart the command prompt I have to redefine the APP_SETTINGS and DATABASE_URL variables. The app works fine after I refine the variables, but I know this isn't the way its supposed to work. The errors are below:
Traceback (most recent call last):
File "app.py", line 12, in <module>
app.config.from_object(os.environ['APP_SETTINGS'])
File "C:\envs\acme\lib\os.py", line 423, in __getitem__
return self.data[key.upper()]
KeyError: 'APP_SETTINGS'
I'll then redefine the variable using "set":
set APP_SETTINGS=config.DevelopmentConfig
Here is the code I use for my app.py and config.py
config.py:
import os
# default config
class BaseConfig(object):
DEBUG = False
SECRET_KEY = 'secret key'
SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']
class DevelopmentConfig(BaseConfig):
DEBUG = True
class ProductionConfig(BaseConfig):
DEBUG = False
app.py
import os
app.config.from_object(os.environ['APP_SETTINGS'])
The same thing goes for the DATABASE_URL variable listed above in the config.py file. I also get a KEYERROR and must redefine the variable using "set" as well as type in my username and password below:
set DATABASE_URL=postgres://username:password@localhost/discover_flask_dev
I'm using Windows 8 and Python 2.7. I have these tools installed in my environment:
Flask==0.10.1
Flask-SQLAlchemy==2.0
Jinja2==2.7.3
MarkupSafe==0.23
SQLAlchemy==0.9.8
Werkzeug==0.9.6
gunicorn==19.1.1
ipython==2.3.0
itsdangerous==0.24
psycopg2==2.5.2
pyreadline==2.0
I'm assuming there is a basic method to solve my problem mentioned above. Please advice. Thanks!