From a0d630d9bff04757e6218493c9079f2b67bd753d Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 28 Jun 2018 08:31:11 +0200 Subject: [PATCH] Load configuration based on the ENV environment variable --- .gitignore | 2 +- app/__init__.py | 7 ++++++- app/config_dev.py | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 app/config_dev.py diff --git a/.gitignore b/.gitignore index ba0430d..c18dd8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -__pycache__/ \ No newline at end of file +__pycache__/ diff --git a/app/__init__.py b/app/__init__.py index 201849e..75430c9 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -14,13 +14,18 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import os + from flask import Flask, render_template class CalendarSocialApp(Flask): - def __init__(self, name): + def __init__(self, name, config=None): Flask.__init__(self, name) + config_name = os.environ.get('ENV', config or 'dev') + self.config.from_pyfile(f'config_{config_name}.py', True) + app = CalendarSocialApp(__name__) diff --git a/app/config_dev.py b/app/config_dev.py new file mode 100644 index 0000000..88c898f --- /dev/null +++ b/app/config_dev.py @@ -0,0 +1,2 @@ +DEBUG = True +ENV = 'dev'