-
-
Save Whatapalaver/0eef073c51ff870cf43c6ccfb904d62e to your computer and use it in GitHub Desktop.
Flask - Dev and Prod Configuration Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sensible defaults for development | |
CONFIGURATION_SETUP=config.DevelopmentConfig | |
HOST_SERVER=test | |
HOST_SERVER_URL="https://placeholder_for_test.com" | |
SECRET_KEY="1234" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import environ | |
class Config(object): | |
"""Base config""" | |
SECRET_KEY = environ.get("SECRET_KEY") or "top-secret" | |
HOST_SERVER = environ.get("HOST_SERVER") | |
HOST_SERVER_URL = environ.get("HOST_SERVER_URL") | |
class ProductionConfig(Config): | |
FLASK_ENV = "production" | |
DEBUG = False | |
TESTING = False | |
class DevelopmentConfig(Config): | |
ENV = "dev" | |
FLASK_ENV = "development" | |
DEBUG = True | |
TESTING = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from os import environ | |
app = Flask(__name__) | |
environment_configuration = environ.get( | |
"CONFIGURATION_SETUP", "config.ProductionConfig" | |
) | |
app.config.from_object(environment_configuration) | |
@app.route("/env") | |
def env(): | |
return f"FLASK_ENV = { app.config['FLASK_ENV']} | ENV = { app.config['ENV']} | SECRET = { app.config['SECRET_KEY']} | SERVER_URL= { app.config['HOST_SERVER_URL']}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment