當前位置: 首頁>>代碼示例>>Python>>正文


Python app.config方法代碼示例

本文整理匯總了Python中config_package_app.app.config方法的典型用法代碼示例。如果您正苦於以下問題:Python app.config方法的具體用法?Python app.config怎麽用?Python app.config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在config_package_app.app的用法示例。


在下文中一共展示了app.config方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_config_from_envvar

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_envvar(self):
        env = os.environ
        try:
            os.environ = {}
            app = flask.Flask(__name__)
            try:
                app.config.from_envvar('FOO_SETTINGS')
            except RuntimeError as e:
                self.assert_true("'FOO_SETTINGS' is not set" in str(e))
            else:
                self.assert_true(0, 'expected exception')
            self.assert_false(app.config.from_envvar('FOO_SETTINGS', silent=True))

            os.environ = {'FOO_SETTINGS': __file__.rsplit('.', 1)[0] + '.py'}
            self.assert_true(app.config.from_envvar('FOO_SETTINGS'))
            self.common_object_test(app)
        finally:
            os.environ = env 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:20,代碼來源:config.py

示例2: test_config_from_envvar_missing

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_envvar_missing(self):
        env = os.environ
        try:
            os.environ = {'FOO_SETTINGS': 'missing.cfg'}
            try:
                app = flask.Flask(__name__)
                app.config.from_envvar('FOO_SETTINGS')
            except IOError as e:
                msg = str(e)
                self.assert_true(msg.startswith('[Errno 2] Unable to load configuration '
                                            'file (No such file or directory):'))
                self.assert_true(msg.endswith("missing.cfg'"))
            else:
                self.fail('expected IOError')
            self.assertFalse(app.config.from_envvar('FOO_SETTINGS', silent=True))
        finally:
            os.environ = env 
開發者ID:rui7157,項目名稱:Flask-NvRay-Blog,代碼行數:19,代碼來源:config.py

示例3: common_object_test

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def common_object_test(self, app):
        self.assert_equal(app.secret_key, 'devkey')
        self.assert_equal(app.config['TEST_KEY'], 'foo')
        self.assert_not_in('ConfigTestCase', app.config) 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:6,代碼來源:config.py

示例4: test_config_from_file

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_file(self):
        app = flask.Flask(__name__)
        app.config.from_pyfile(__file__.rsplit('.', 1)[0] + '.py')
        self.common_object_test(app) 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:6,代碼來源:config.py

示例5: test_config_from_object

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_object(self):
        app = flask.Flask(__name__)
        app.config.from_object(__name__)
        self.common_object_test(app) 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:6,代碼來源:config.py

示例6: test_config_from_class

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_from_class(self):
        class Base(object):
            TEST_KEY = 'foo'
        class Test(Base):
            SECRET_KEY = 'devkey'
        app = flask.Flask(__name__)
        app.config.from_object(Test)
        self.common_object_test(app) 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:10,代碼來源:config.py

示例7: test_config_missing

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_config_missing(self):
        app = flask.Flask(__name__)
        try:
            app.config.from_pyfile('missing.cfg')
        except IOError as e:
            msg = str(e)
            self.assert_true(msg.startswith('[Errno 2] Unable to load configuration '
                                        'file (No such file or directory):'))
            self.assert_true(msg.endswith("missing.cfg'"))
        else:
            self.assert_true(0, 'expected config')
        self.assert_false(app.config.from_pyfile('missing.cfg', silent=True)) 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:14,代碼來源:config.py

示例8: test_session_lifetime

# 需要導入模塊: from config_package_app import app [as 別名]
# 或者: from config_package_app.app import config [as 別名]
def test_session_lifetime(self):
        app = flask.Flask(__name__)
        app.config['PERMANENT_SESSION_LIFETIME'] = 42
        self.assert_equal(app.permanent_session_lifetime.seconds, 42) 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:6,代碼來源:config.py


注:本文中的config_package_app.app.config方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。