【发布时间】:2019-03-31 18:43:29
【问题描述】:
我正在运行一个烧瓶应用程序,该应用程序正在运行但未遵循我设置的配置。这是配置文件
import os
class Config(object):
"parent configuration class"
DEBUG= True
class DevelopmentConfig(Config):
"Configurations for Development"
DEBUG = True
connectionVariables="dbname='store-manager' user='postgres' password="1235" host='localhost' port='5432'"
os.environ['ENVIRONMENT']='development'
class TestingConfig(Config):
"""Configurations for Testing,"""
TESTING = True
DEBUG = True
connectionVariables="dbname='store-manager-test' user='postgres' password="1235" host='localhost' port='5432'"
os.environ['ENVIRONMENT']='testing'
app_config = {
'development': DevelopmentConfig,
'testing': TestingConfig
}
每当我运行应用程序时,即使我指定了开发,它也会在测试模式下运行,但是,如果我删除测试配置,它会在开发环境下运行。 这就是我创建应用程序的方式
from flask import Flask
from flask_restful import Api
from instance.config import app_config
from connection import DbBase
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(app_config[config_name])
return app
这就是运行它的方式。
import os
from app import create_app
config_name = 'development'
app = create_app(config_name)
# method to run app.py
if __name__ == '__main__':
app.run()
【问题讨论】:
-
你的配置文件的全名是什么? development.cfg?
-
我已将其命名为 config.py
标签: python flask configuration