Issue running Flask App: create_app app.config.from_object(app_config[config_name]) KeyError: NoneHeroku /Flask/Postgres: Can not connect to serverFlask with create_app, SQLAlchemy and CeleryShare sqlalchemy models between flask and other appsFlask: need clarification on run, config, and setup layoutError processing Json requestRunning my Python script in my virtual env?Flask - cannot use Flask and Flask-mail instances from other filesFlask-PyMongo - init_app() missing 1 required positional argument: 'app'Using 'flask run' does not enable debugger…why?How can I run an app script python in django (hosted in a2hosting)?

Why Lie algebras if what we care about in physics are groups?

Function pointer parameter without asterisk

Impact of throwing away fruit waste on a peak > 3200 m above a glacier

Killing a star safely

Source for "everyone has a specific area of Torah that they're naturally drawn to"

Does switching on an old games console without a cartridge damage it?

1025th term of the given sequence.

What do Unicorns want?

"It is what it is"

How can I deal with someone that wants to kill something that isn't supposed to be killed?

Is it better to have a 10 year gap or a bad reference?

Host telling me to cancel my booking in exchange for a discount?

Magic is the twist

Why do we need an estimator to be consistent?

What is the best word describing the nature of expiring in a short amount of time, connoting "losing public attention"?

My current job follows "worst practices". How can I talk about my experience in an interview without giving off red flags?

Is it ethical to tell my teaching assistant that I like him?

How can I disable a reserved profile?

Can someone clarify when a Trigger executes on a single record vs. multiple in one context?

Is it better to merge "often" or only after completion do a big merge of feature branches?

Counterexample finite intersection property

Are there any English words pronounced with sounds/syllables that aren't part of the spelling?

What would be the effects of (relatively) widespread precognition on the stock market?

Why didn't NASA launch communications relay satellites for the Apollo missions?



Issue running Flask App: create_app app.config.from_object(app_config[config_name]) KeyError: None


Heroku /Flask/Postgres: Can not connect to serverFlask with create_app, SQLAlchemy and CeleryShare sqlalchemy models between flask and other appsFlask: need clarification on run, config, and setup layoutError processing Json requestRunning my Python script in my virtual env?Flask - cannot use Flask and Flask-mail instances from other filesFlask-PyMongo - init_app() missing 1 required positional argument: 'app'Using 'flask run' does not enable debugger…why?How can I run an app script python in django (hosted in a2hosting)?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I downloaded a Flask project from GitHub. I'm trying to run the Flask project in a virtualenv, but when I run the project in virtualenv it's throwing the following error:




none
app__init__.py", line 10, in create_app
app.config.from_object(app_config[config_name])
KeyError: None




__init__.py:



from flask import Flask
from config import app_config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

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)
migrate = Migrate(app, db)
from app import models
from app.home import home as home_blueprint
app.register_blueprint(home_blueprint)
return app


config.py:



 class Config(object):
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_ECHO = True
class ProductionConfig(Config):
DEBUG = False

app_config =
'development': DevelopmentConfig,
'production': ProductionConfig



run.py:



 import os
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
if __name__ == '__main__':
app.run()









share|improve this question
























  • Is config_name None?

    – Ilja Everilä
    Mar 26 at 13:32











  • Your question is missing a word at the end of the first sentence. Is the missing word "virtualenv"?

    – karel
    Mar 26 at 13:38












  • @karel Yes, Thank you.

    – user8624996
    Mar 26 at 13:41











  • @Ilja Everilä I'll update my config.py code.

    – user8624996
    Mar 26 at 13:42

















0















I downloaded a Flask project from GitHub. I'm trying to run the Flask project in a virtualenv, but when I run the project in virtualenv it's throwing the following error:




none
app__init__.py", line 10, in create_app
app.config.from_object(app_config[config_name])
KeyError: None




__init__.py:



from flask import Flask
from config import app_config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

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)
migrate = Migrate(app, db)
from app import models
from app.home import home as home_blueprint
app.register_blueprint(home_blueprint)
return app


config.py:



 class Config(object):
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_ECHO = True
class ProductionConfig(Config):
DEBUG = False

app_config =
'development': DevelopmentConfig,
'production': ProductionConfig



run.py:



 import os
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
if __name__ == '__main__':
app.run()









share|improve this question
























  • Is config_name None?

    – Ilja Everilä
    Mar 26 at 13:32











  • Your question is missing a word at the end of the first sentence. Is the missing word "virtualenv"?

    – karel
    Mar 26 at 13:38












  • @karel Yes, Thank you.

    – user8624996
    Mar 26 at 13:41











  • @Ilja Everilä I'll update my config.py code.

    – user8624996
    Mar 26 at 13:42













0












0








0








I downloaded a Flask project from GitHub. I'm trying to run the Flask project in a virtualenv, but when I run the project in virtualenv it's throwing the following error:




none
app__init__.py", line 10, in create_app
app.config.from_object(app_config[config_name])
KeyError: None




__init__.py:



from flask import Flask
from config import app_config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

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)
migrate = Migrate(app, db)
from app import models
from app.home import home as home_blueprint
app.register_blueprint(home_blueprint)
return app


config.py:



 class Config(object):
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_ECHO = True
class ProductionConfig(Config):
DEBUG = False

app_config =
'development': DevelopmentConfig,
'production': ProductionConfig



run.py:



 import os
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
if __name__ == '__main__':
app.run()









share|improve this question
















I downloaded a Flask project from GitHub. I'm trying to run the Flask project in a virtualenv, but when I run the project in virtualenv it's throwing the following error:




none
app__init__.py", line 10, in create_app
app.config.from_object(app_config[config_name])
KeyError: None




__init__.py:



from flask import Flask
from config import app_config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

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)
migrate = Migrate(app, db)
from app import models
from app.home import home as home_blueprint
app.register_blueprint(home_blueprint)
return app


config.py:



 class Config(object):
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_ECHO = True
class ProductionConfig(Config):
DEBUG = False

app_config =
'development': DevelopmentConfig,
'production': ProductionConfig



run.py:



 import os
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
if __name__ == '__main__':
app.run()






python flask virtualenv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 15:10









Nathan

2,7863 gold badges4 silver badges23 bronze badges




2,7863 gold badges4 silver badges23 bronze badges










asked Mar 26 at 13:08







user8624996



















  • Is config_name None?

    – Ilja Everilä
    Mar 26 at 13:32











  • Your question is missing a word at the end of the first sentence. Is the missing word "virtualenv"?

    – karel
    Mar 26 at 13:38












  • @karel Yes, Thank you.

    – user8624996
    Mar 26 at 13:41











  • @Ilja Everilä I'll update my config.py code.

    – user8624996
    Mar 26 at 13:42

















  • Is config_name None?

    – Ilja Everilä
    Mar 26 at 13:32











  • Your question is missing a word at the end of the first sentence. Is the missing word "virtualenv"?

    – karel
    Mar 26 at 13:38












  • @karel Yes, Thank you.

    – user8624996
    Mar 26 at 13:41











  • @Ilja Everilä I'll update my config.py code.

    – user8624996
    Mar 26 at 13:42
















Is config_name None?

– Ilja Everilä
Mar 26 at 13:32





Is config_name None?

– Ilja Everilä
Mar 26 at 13:32













Your question is missing a word at the end of the first sentence. Is the missing word "virtualenv"?

– karel
Mar 26 at 13:38






Your question is missing a word at the end of the first sentence. Is the missing word "virtualenv"?

– karel
Mar 26 at 13:38














@karel Yes, Thank you.

– user8624996
Mar 26 at 13:41





@karel Yes, Thank you.

– user8624996
Mar 26 at 13:41













@Ilja Everilä I'll update my config.py code.

– user8624996
Mar 26 at 13:42





@Ilja Everilä I'll update my config.py code.

– user8624996
Mar 26 at 13:42












1 Answer
1






active

oldest

votes


















0














I think you forgot to set your FLASK_CONFIG environment variable before trying to run your Flask app. This will cause your environment configuration lookup to fail i.e. app_config[config_name] will be None since config_name isn't instantiated. Can you try setting up your environment variables before running? For example, open up your terminal and set your FLASK_CONFIG environment variable to development then try rerunning your application, something along the lines of:



 # Macintosh Users
export FLASK_CONFIG=development
export FLASK_APP=<start_file> # <start_file> is probably run.py for the template
flask run

# Window Users
set FLASK_CONFIG=development
set FLASK_APP=run.py
flask run


Hopefully that helps, if this doesn't solve your issue can you please paste your file which starts your application? This file is probably run.py






share|improve this answer

























  • Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

    – user8624996
    Mar 26 at 14:24











  • Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

    – Nathan
    Mar 26 at 15:04











  • No I'm using windows 10

    – user8624996
    Mar 26 at 15:08











  • Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

    – Nathan
    Mar 26 at 15:12











  • Yes, I'll try now asap. Thank you for providing the reference.

    – user8624996
    Mar 26 at 15:14










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357986%2fissue-running-flask-app-create-app-app-config-from-objectapp-configconfig-nam%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think you forgot to set your FLASK_CONFIG environment variable before trying to run your Flask app. This will cause your environment configuration lookup to fail i.e. app_config[config_name] will be None since config_name isn't instantiated. Can you try setting up your environment variables before running? For example, open up your terminal and set your FLASK_CONFIG environment variable to development then try rerunning your application, something along the lines of:



 # Macintosh Users
export FLASK_CONFIG=development
export FLASK_APP=<start_file> # <start_file> is probably run.py for the template
flask run

# Window Users
set FLASK_CONFIG=development
set FLASK_APP=run.py
flask run


Hopefully that helps, if this doesn't solve your issue can you please paste your file which starts your application? This file is probably run.py






share|improve this answer

























  • Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

    – user8624996
    Mar 26 at 14:24











  • Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

    – Nathan
    Mar 26 at 15:04











  • No I'm using windows 10

    – user8624996
    Mar 26 at 15:08











  • Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

    – Nathan
    Mar 26 at 15:12











  • Yes, I'll try now asap. Thank you for providing the reference.

    – user8624996
    Mar 26 at 15:14















0














I think you forgot to set your FLASK_CONFIG environment variable before trying to run your Flask app. This will cause your environment configuration lookup to fail i.e. app_config[config_name] will be None since config_name isn't instantiated. Can you try setting up your environment variables before running? For example, open up your terminal and set your FLASK_CONFIG environment variable to development then try rerunning your application, something along the lines of:



 # Macintosh Users
export FLASK_CONFIG=development
export FLASK_APP=<start_file> # <start_file> is probably run.py for the template
flask run

# Window Users
set FLASK_CONFIG=development
set FLASK_APP=run.py
flask run


Hopefully that helps, if this doesn't solve your issue can you please paste your file which starts your application? This file is probably run.py






share|improve this answer

























  • Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

    – user8624996
    Mar 26 at 14:24











  • Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

    – Nathan
    Mar 26 at 15:04











  • No I'm using windows 10

    – user8624996
    Mar 26 at 15:08











  • Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

    – Nathan
    Mar 26 at 15:12











  • Yes, I'll try now asap. Thank you for providing the reference.

    – user8624996
    Mar 26 at 15:14













0












0








0







I think you forgot to set your FLASK_CONFIG environment variable before trying to run your Flask app. This will cause your environment configuration lookup to fail i.e. app_config[config_name] will be None since config_name isn't instantiated. Can you try setting up your environment variables before running? For example, open up your terminal and set your FLASK_CONFIG environment variable to development then try rerunning your application, something along the lines of:



 # Macintosh Users
export FLASK_CONFIG=development
export FLASK_APP=<start_file> # <start_file> is probably run.py for the template
flask run

# Window Users
set FLASK_CONFIG=development
set FLASK_APP=run.py
flask run


Hopefully that helps, if this doesn't solve your issue can you please paste your file which starts your application? This file is probably run.py






share|improve this answer















I think you forgot to set your FLASK_CONFIG environment variable before trying to run your Flask app. This will cause your environment configuration lookup to fail i.e. app_config[config_name] will be None since config_name isn't instantiated. Can you try setting up your environment variables before running? For example, open up your terminal and set your FLASK_CONFIG environment variable to development then try rerunning your application, something along the lines of:



 # Macintosh Users
export FLASK_CONFIG=development
export FLASK_APP=<start_file> # <start_file> is probably run.py for the template
flask run

# Window Users
set FLASK_CONFIG=development
set FLASK_APP=run.py
flask run


Hopefully that helps, if this doesn't solve your issue can you please paste your file which starts your application? This file is probably run.py







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 15:44

























answered Mar 26 at 14:17









NathanNathan

2,7863 gold badges4 silver badges23 bronze badges




2,7863 gold badges4 silver badges23 bronze badges












  • Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

    – user8624996
    Mar 26 at 14:24











  • Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

    – Nathan
    Mar 26 at 15:04











  • No I'm using windows 10

    – user8624996
    Mar 26 at 15:08











  • Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

    – Nathan
    Mar 26 at 15:12











  • Yes, I'll try now asap. Thank you for providing the reference.

    – user8624996
    Mar 26 at 15:14

















  • Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

    – user8624996
    Mar 26 at 14:24











  • Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

    – Nathan
    Mar 26 at 15:04











  • No I'm using windows 10

    – user8624996
    Mar 26 at 15:08











  • Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

    – Nathan
    Mar 26 at 15:12











  • Yes, I'll try now asap. Thank you for providing the reference.

    – user8624996
    Mar 26 at 15:14
















Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

– user8624996
Mar 26 at 14:24





Thank you for your detailed explanation. I'm trying to setting the environment variable. I'll add the main file which is starting app.

– user8624996
Mar 26 at 14:24













Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

– Nathan
Mar 26 at 15:04





Ok so my explanation is the reason why, this line within run.py: config_name = os.getenv('FLASK_CONFIG') is looking for the environment variable FLASK_CONFIG so it can choose the appropriate configuration. Are you on a Macintosh?

– Nathan
Mar 26 at 15:04













No I'm using windows 10

– user8624996
Mar 26 at 15:08





No I'm using windows 10

– user8624996
Mar 26 at 15:08













Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

– Nathan
Mar 26 at 15:12





Ok can you try: set FLASK_CONFIG=development then: set FLASK_APP=run.py then: flask run For reference: flask.pocoo.org/docs/dev/cli and see if that works?

– Nathan
Mar 26 at 15:12













Yes, I'll try now asap. Thank you for providing the reference.

– user8624996
Mar 26 at 15:14





Yes, I'll try now asap. Thank you for providing the reference.

– user8624996
Mar 26 at 15:14








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357986%2fissue-running-flask-app-create-app-app-config-from-objectapp-configconfig-nam%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript