1
Traceback (most recent call last):
File "app.py", line 14, in <module>
app.config.from_object(os.environ['APP_SETTINGS'])
File "/Users/nihit/Desktop/flask-intro/venv/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'APP_SETTINGS'

I get this errors when I try to run my app.py, my config.py I learning from an online tutorial using flask this is the first few lines of codes in my app folder.

# import the Flask class from the flask module
from flask import Flask, render_template, redirect, \
url_for, request, session, flash
from functools import wraps
from flask.ext.sqlalchemy import SQLAlchemy



# create the application object
app = Flask(__name__)

# config
import os
app.config.from_object(os.environ['APP_SETTINGS'])

# create the sqlalchemy object
db = SQLAlchemy(app)

# import db schema
from models import *

my config.py import os

# default config
class BaseConfig(object):
DEBUG = False
# shortened for readability
SECRET_KEY = 'secret key'
SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']


class DevelopmentConfig(BaseConfig):
DEBUG = True


class ProductionConfig(BaseConfig):
DEBUG = False

I hope someone can help me to identify what I am doing wrong, I am following this online tutorial to learn , so most of the things are there https://www.youtube.com/watch?v=Up3p20rgWCw&list=PLLjmbh6XPGK5e0IbpMccp7NmJHnN8O1ng&index=28

Masnad Hossain
  • 59
  • 1
  • 1
  • 14

1 Answers1

0

You are missing the APP_SETTINGS environment variable. Define that and you'll be good to go.

export APP_SETTINGS=config.DevelopmentConfig

I'm not sure where this is first discussed in the tutorial, but you can see it about 4 minutes into the video you linked to when the author discusses adding the DATABASE_URL environment variable.

dirn
  • 19,454
  • 5
  • 69
  • 74
  • Thanks for the help I guess it worked but later in about 6 minutes of the video the author created a db_create.py and i followed the same example but I am getting a error which says Traceback (most recent call last): File "db_create.py", line 6, in db.create_all() Library not loaded: libssl.1.0.0.dylib Referenced from: /Users/nihit/Desktop/flask-intro/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so Reason: image not found CAN YOU HELP ME OUT – Masnad Hossain Dec 23 '14 at 22:08
  • How did you install Postgres? – dirn Dec 23 '14 at 22:13
  • i am using the postgre app that was told in the tutorial – Masnad Hossain Dec 23 '14 at 23:18
  • There are a lot of questions on SO about this error. They all suggest that `psycopg2` needs to be installed again using the newer version of `openssl`. Some folks suggest environment variables. Others suggest using symlinks. If none of those work for you, you should ask this as a new question so people can answer it. – dirn Dec 24 '14 at 14:42
  • I found out a post which helped me out, Thanks for your help , appreciate it – Masnad Hossain Dec 24 '14 at 14:49