Reputation: 61
I just study working with Flask and don`t understand why my code is not working. Here it is:
#run py
import os
from app.create_app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
if __name__ == "__main__":
app.run(debug=True)
#create_app.py
from config import app_config
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app(config_name):
app = Flask(__name__, instance_relative_config=True)
app.config.from_object(app_config[config_name])
app.config.from_pyfile('config.py')
db.init_app(app)
return app
#config.py
class Config(object):
"""
Common configurations
"""
# Put any configurations here that are common across all environments
class DevelopmentConfig(Config):
"""
Development configurations
"""
DEBUG = True
SQLALCHEMY_ECHO = True
class ProductionConfig(Config):
"""
Production configurations
"""
DEBUG = False
app_config = {
'development': DevelopmentConfig,
'production': ProductionConfig
}
When I run my app I just get this error:
Traceback (most recent call last):
File "<input>", line 7, in <module>
File "C:\Users\Dess\Desktop\iv\flask\app\create_app.py", line 27, in create_app
NameError: name 'app_config' is not defined
I pointed out app_config in create_app, but run.py didn`t find it. I would be glad for your help
Upvotes: 0
Views: 6102