Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flask-Script: demo passing in configuration file.

This demonstrates that you can configure a Flask application through Flask-Script, without having to create a Flask instance or deal with circular dependencies. Note that Flask-Script's Manager accepts a factory function in place of a Flask app object.


python runserver

gives "Hello, world!" on http://localhost:5000/, while running:

python runserver -c development.cfg

gives "Hello, developer!".

import os
from flask import Flask
def create_app(config=None):
app = Flask(__name__)
if config is None:
config = os.path.join(app.root_path, 'production.cfg')
def index():
return 'Hello, %(name)s!' % {'name': app.config['HELLO']}
return app
HELLO = 'developer'
from flask.ext.script import Manager
from app import create_app
manager = Manager(create_app)
manager.add_option('-c', '--config', dest='config', required=False)
if __name__ == '__main__':
HELLO = 'world'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.