【问题标题】:Flask app not running on development configurationFlask 应用程序未在开发配置上运行
【发布时间】: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


【解决方案1】:

根据您实际运行它的方式以及在什么平台上,您需要确保指定 config.file 的位置。

export YOURAPPLICATION_SETTINGS=/path/to/settings.cfg

或用于窗户

set YOURAPPLICATION_SETTINGS=\path\to\settings.cfg

我在上面的描述中没有看到它,所以这可能是问题所在。

Flask Doc on using a config File

【讨论】:

    猜你喜欢
    • 2015-05-19
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2020-07-15
    相关资源
    最近更新 更多