Flask run command not respecting config file env var

时间:2019-01-09 22:19:14

标签: python flask

When I call flask run, the app itself is not respecting my local env configuration. Im expecting the environment to be in debug mode and development, but the console output says otherwise

flask run
* Serving Flask app "flaskr/app.py"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
<Config {'ENV': 'development', 'DEBUG': True, 'TESTING': False, 
'PROPAGATE_EXCEPTIONS': None, 'PRESERVE_CONTEXT_ON_EXCEPTION': None, 
'SECRET_KEY': 'this-really-needs-to-be-changed', 
'PERMANENT_SESSION_LIFETIME': datetime.timedelta(days=31), 
'USE_X_SENDFILE': False, 'SERVER_NAME': None, 'APPLICATION_ROOT': '/', 
'SESSION_COOKIE_NAME': 'session', 'SESSION_COOKIE_DOMAIN': None, 
'SESSION_COOKIE_PATH': None, 'SESSION_COOKIE_HTTPONLY': True, 
'SESSION_COOKIE_SECURE': False, 'SESSION_COOKIE_SAMESITE': None, 
'SESSION_REFRESH_EACH_REQUEST': True, 'MAX_CONTENT_LENGTH': None, 
'SEND_FILE_MAX_AGE_DEFAULT': datetime.timedelta(seconds=43200), 
'TRAP_BAD_REQUEST_ERRORS': None, 'TRAP_HTTP_EXCEPTIONS': False, 
'EXPLAIN_TEMPLATE_LOADING': False, 'PREFERRED_URL_SCHEME': 'http', 
'JSON_AS_ASCII': True, 'JSON_SORT_KEYS': True, 
'JSONIFY_PRETTYPRINT_REGULAR': False, 'JSONIFY_MIMETYPE': 
'application/json', 'TEMPLATES_AUTO_RELOAD': None, 'MAX_COOKIE_SIZE': 4093, 'CSRF_ENABLED': True, 'DEVELOPMENT': True}>

config.py file

import os
basedir = os.path.abspath(os.path.dirname(__file__))


class Config(object):
    DEBUG = False
    TESTING = False
    CSRF_ENABLED = True
    SECRET_KEY = 'this-really-needs-to-be-changed'


class ProductionConfig(Config):
    DEBUG = False


class StagingConfig(Config):
    DEVELOPMENT = True
    DEBUG = True


class DevelopmentConfig(Config):
    ENV = 'development'
    DEVELOPMENT = True
    DEBUG = True


class TestingConfig(Config):
    TESTING = True

app.py file

app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
logger = app.logger


print(app.config)

Am i missing something or misunderstanding how the Flask CLI works?

0 个答案:

没有答案