Last active
March 25, 2020 09:26
-
-
Save diegoquintanav/3d67393ba7624457ad703eeee320c152 to your computer and use it in GitHub Desktop.
instance configuration in Flask
This file contains 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
## instance/config.py | |
HELLO_ENABLED = False |
This file contains 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 | |
import os | |
class Config: | |
"""basic configuration parameters passed to the Flask app""" | |
# basic config | |
SECRET_KEY = 'changeme' | |
WTF_CSRF_SECRET_KEY = 'changemetoo' | |
DEBUG=True | |
# application feature flags | |
HELLO_ENABLED = True | |
app = Flask(__name__, instance_relative_config=True) | |
app.config.from_object(Config) | |
# override default settings with those present in /instance/config.py | |
# this will raise an exception if file is not present | |
app.config.from_pyfile('config.py') | |
@app.route('/') | |
def hello_world(): | |
if app.config['HELLO_ENABLED']: | |
return 'helloworld' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment