diff --git a/python-flask-example-heroku/.gitignore b/python-flask-example-heroku/.gitignore index 5ceb3864c2911029f0a6010fadab352e4b8e2d07..d75edeaec0ee8b547be47de1ceacdec0a414aeed 100644 --- a/python-flask-example-heroku/.gitignore +++ b/python-flask-example-heroku/.gitignore @@ -1 +1,2 @@ venv +__pycache__ \ No newline at end of file diff --git a/python-flask-example-heroku/app.py b/python-flask-example-heroku/app.py index 82b9e4511b750b06c0448d5ee7cf60ad1e287d16..a80c6dd6fb35103e89cde774475866caf186ce9f 100644 --- a/python-flask-example-heroku/app.py +++ b/python-flask-example-heroku/app.py @@ -2,9 +2,11 @@ import os from flask import Flask app = Flask(__name__) -app.config.from_object(os.getenv("APP_SETTINGS", "config.DevelopmentConfig")) +env_config = os.getenv("APP_SETTINGS", "config.DevelopmentConfig") +app.config.from_object(env_config) @app.route("/") def index(): - return f"The configured secret key is {app.config.get('SECRET_KEY')}" + secret_key = app.config.get("SECRET_KEY") + return f"The configured secret key is {secret_key}." diff --git a/python-flask-example-heroku/config.py b/python-flask-example-heroku/config.py index 15ebf6c77804f73c7203ecdb4cf578493209c00a..40d3c4dec3efc74fb6b305dbb9ed2f9fa28aca5b 100644 --- a/python-flask-example-heroku/config.py +++ b/python-flask-example-heroku/config.py @@ -1,21 +1,20 @@ import os -class Config(object): +class Config: DEBUG = False - TESTING = False - SECRET_KEY = os.getenv("SECRET_KEY", "this-is-read-from-env") + DEVELOPMENT = False + SECRET_KEY = os.getenv("SECRET_KEY", "this-is-the-default-key") class ProductionConfig(Config): - DEBUG = False + pass class StagingConfig(Config): - DEVELOPMENT = True DEBUG = True class DevelopmentConfig(Config): - DEVELOPMENT = True DEBUG = True + DEVELOPMENT = True