Exemple #1
0
def create_app(env_name):
    """
    Create app
    """

    # app initiliazation
    app = Flask(__name__)
    CORS(app)

    app.config.from_object(app_config[env_name])

    # initializing bcrypt and db
    bcrypt.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    migrate = Migrate(app, db)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)

    if __name__ == '__main__':
        manager.run()

    # Route
    api = Api(app)

    # user endpoint
    api.add_resource(Login, '/auth/login')
    api.add_resource(Register, '/auth/register')

    return app
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'myblog.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # a simple page that says hello
    db.init_app(app)
    #app.register_blueprint(auth.bp)
    #app.register_blueprint(blog.bp)
    #app.add_url_rule('/', endpoint='index')
    app.register_blueprint(lone.bp)
    '''
    @app.route('/hello')
    def hello():
        return 'This is test!'obg
    '''
    return app
Exemple #3
0
def create_app(package_name, package_path, settings_override=None):
    """
    This function creates the application using the application factory pattern.
    Extensions and blueprints are then initialized onto the the application
    object.

    http://flask.pocoo.org/docs/0.11/patterns/appfactories/

    :param package_name: the name of the package
    :param package_path: the path of the package
    :param settings_override: override default settings via a python object
    :return: app: the main flask application object
    """
    app = Flask(package_name,
                instance_relative_config=True,
                template_folder='templates')
    app.config.from_pyfile('config.py', silent=True)

    if settings_override:
        app.config.from_object(settings_override)

    # Attach Flask Extensions
    db.init_app(app)

    # Register Blueprints
    app.register_blueprint(home, url_prefix="/")


    return app
Exemple #4
0
def create_app(test_config=None):

    # create the app and load config variables
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY=os.environ.get('SECRET_KEY') or 'dev',
        SQLALCHEMY_DATABASE_URI=os.environ.get('DATABASE_URL', 'sqlite:///capstone-project.sqlite'),
        SQLALCHEMY_TRACK_MODIFICATIONS=False
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # initialize the db
    db.init_app(app)

    # ROUTES

    # main page
    app.register_blueprint(index.bp)
    app.add_url_rule('/', endpoint='index')

    # login and registration
    app.register_blueprint(auth.bp)

    # admin
    app.register_blueprint(admin.bp)

    return app
Exemple #5
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(
        __name__,
    )

    # TODO: collapse with below
    app_config = getConfig(app)
    app.config.from_object(app_config)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile("config.py", silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    db.init_app(app)
    auth.init_app(app)
    app.register_blueprint(files.views.bp)

    app.add_url_rule("/", endpoint="index", view_func=files.views.index)

    return app
Exemple #6
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=(app.instance_path, 'moneykeeper.sql'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load test config if exists
        app.config.from_mapping(test_config)

    # ensure that directory is exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # simple webpage
    @app.route('/welcome')
    def welcome() -> str:
        return 'Welcome to Moneykeeper'

    db.init_app(app)

    return app
Exemple #7
0
def create_app(test_config=None, debug=False):
    # create and configure the app
    app = Flask(__name__)
    app.debug = debug
    app.jinja_options = dict(autoescape=select_autoescape(default=True),
                             trim_blocks=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.root_path, 'database/database.sqlite'),
    )
    app.config['SECRET_KEY'] = 'ARTK'
    jsglue = JSGlue(app)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    db.init_app(app)
    app.register_blueprint(home.bp)
    app.register_blueprint(packer.bp)
    app.register_blueprint(docs.bp, url_prefix='/docs')
    app.register_blueprint(node.bp, url_prefix='/node')
    app.register_blueprint(projects.bp, url_prefix='/projects')
    app.register_blueprint(editor.bp, url_prefix='/edit')

    socketio.init_app(app)
    messages.init_sockets(socketio)
    editor.init_sockets(socketio)

    return app
    def __init__(self, test_config=None):
        app = Flask(__name__)
        # create and configure the app
        app = Flask(__name__, instance_relative_config=True)
        CORS(app, supports_credentials=True)
        app.config.from_mapping(
            SECRET_KEY='dev',
            DATABASE=os.path.join(app.instance_path, 'chrome.sqlite'),
        )

        if test_config is None:
            # load the instance config, if it exists, when not testing
            app.config.from_pyfile('config.py', silent=True)
        else:
            # load the tests config if passed in
            app.config.from_mapping(test_config)

        # init db
        db.init_app(app)

        # ensure the instance folder exists
        try:
            os.makedirs(app.instance_path)
        except OSError:
            pass

        # a simple page that says hello
        @app.route('/hello')
        def hello():
            return 'Hello, World!'

        self.app = app
        self.api = Api(self.app)

        pass
Exemple #9
0
def create_app(test_config=None):
    # create and configure the app
    template_dir = os.path.abspath('..')
    app = Flask(__name__,
                instance_relative_config=True,
                template_folder='templates')
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'desi_stack.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    import db
    db.init_app(app)

    import auth
    app.register_blueprint(auth.bp)

    import stack_request
    app.register_blueprint(stack_request.bp)
    app.add_url_rule('/', endpoint='index')

    return app
Exemple #10
0
def configure(app):
	app.config['SECRET_KEY'] = '1488'

	#enabling bleuprints
	app.register_blueprint(post_blueprint.blueprint, url_prefix='/feed')
	app.register_blueprint(admin_blueprint.blueprint, url_prefix='/admin')
	app.register_blueprint(auth_blueprint.blueprint, url_prefix='/auth')
	app.register_blueprint(eng_blueprint.blueprint, url_prefix='/social')

	#enabling debug mode
	app.debug = True
	
	# initialize Mongoengine
	init_app(app)

	# initializing Flask login
	auth_blueprint.login_manager.init_app(app)
	
	# setting up debug toolbar
	#DebugToolbarExtension(app)

	# config bower
	app.config['BOWER_COMPONENTS_ROOT'] = '../bower_components'

	# configuring bower
	Bower(app)
Exemple #11
0
def poster(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE='./instance/flaskr.sqlite',
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs('./instance/')
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    db.init_app(app)

    app.register_blueprint(auth.bp)

    app.register_blueprint(blog.bp)
    app.add_url_rule('/', endpoint='index')

    return app
def init(app):
    """ 初始化后台管理 """

    admin = Admin(
        name=BaseConfig.SITE_NAME,
        index_view=IndexView('仪表盘', menu_icon_value='diamond'),
        base_template='base.html',
    )

    admin.category_icon_classes = {
        u'运营': 'fa fa-hdd-o',
        u'日志': 'fa fa-database',
    }

    # 日志
    admin.add_view(ItemView(Item,           name='系统选项', category='日志'))
    admin.add_view(StatLogView(StatLog,     name='统计日志', category='日志'))
    admin.add_view(TraceLogView(TraceLog,   name='跟踪日志', category='日志'))

    WebStaticAdmin = get_static_admin('WebStaticAdmin')
    admin.add_view(WebStaticAdmin(WebConfig.RELEASE_STATIC_FOLDER,
        'http://{{ cookiecutter.web_host }}/static/', name='文件', menu_icon_value='folder'))

    admin.init_app(app)
    db.init_app(app)
    init_uploads(app)
Exemple #13
0
def init(app):
    db.init_app(app)
    media.init_app(app)
    init_um(app)
    init_routes(app)
    init_uploads(app)
    wapi.init_app(app)
Exemple #14
0
def init(app):
    db.init_app(app)
    media.init_app(app)
    init_um(app)
    init_routes(app)
    init_uploads(app)
    wapi.init_app(app)
Exemple #15
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    db.init_app(app)

    return app
Exemple #16
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object("config.DevelopmentConfig")
    Bootstrap(app)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    import db
    db.init_app(app)
    import checkin
    app.register_blueprint(checkin.bp)

    return app
Exemple #17
0
    def music():
        '''
        Ask database:
        1) mood to search, 
        Searching tracks with recommendations for this mood in spotify 
        2) generated based on for a given seed entity and matched against similar artists and tracks,
        listen 30 sec preview,
        '''
        db = get_db()
        posts = db.execute('SELECT body, mood'
                           ' FROM post'
                           ' ORDER BY id DESC ').fetchone()
        mood = posts['mood']

        # Not related to user token is stored as class TokenStorage object
        token = TOKEN.get_token(time.time())

        # Get data that user post to app on index page
        track = mood

        # Get data in json format from search_tracks request
        found_tracks = search_tracks(token, track)

        return render_template(
            "music.html",
            posts=posts,
            mood=mood,
            mood_emoji=mood_emoji,
            found_tracks=found_tracks,
        )

        db.init_app(app)
Exemple #18
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    import db
    db.init_app(app)

    import auth
    app.register_blueprint(auth.bp)

    import blog
    app.register_blueprint(blog.bp)
    app.add_url_rule('/auth/login', endpoint='auth.login')

    with app.app_context():
        init_db()

    return app
def configure_extensions(app, cli):
    """configure flask extensions
    """
    db.init_app(app)

    if cli is True:
        migrate.init_app(app, db)
def create_app(config=None):
    if config is None:
        config = DevelopmentConfig()

    app = Flask(__name__)

    app.config.from_object(config)
    app.config.from_envvar('{{cookiecutter.app_name|upper}}_CONFIG', silent=True)

    assets.init_app(app)
    assets.from_yaml(app.config['ASSETS'])

    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    babel.init_app(app)
    mail.init_app(app)

    @app.route('/')
    def home():
        return render_template('home.html')

    for name, url_prefix in app.config.get('MODULES', []):
        blueprint = getattr(getattr(modules, name), name)
        app.register_blueprint(blueprint, url_prefix=url_prefix)

    return app
def create_app():
    app = Flask(__name__)
    #Configuracion de la aplicacion
    app.config.from_mapping(
        SECRET_KEY='nosequeponeraquiXD',
        DATABASE_HOST='localhost',
        DATABASE_USER='******',
        DATABASE_PASSWORD='******',
        DATABASE ='todo_list'
    )
    #inicializar el script para conectarse a la database
    import db
    db.init_app(app)

    #Importar y registrar los blueprint de los demas modulos
    import auth
    import user
    import api
    app.register_blueprint(user.bp)
    app.register_blueprint(auth.bp)
    app.register_blueprint(api.bp)
    #Ruta principal
    @app.route('/')
    def index():
        return redirect(url_for('auth.login'))
    return app
def create_app(test_config=None):
    app = Flask(__name__, instance_relative_config=True)

    logging.basicConfig(level=logging.INFO)

    app.config.from_object('flaskr.config.Config')

    if os.getenv('APPLICATION_SETTINGS'):
        app.config.from_envvar('APPLICATION_SETTINGS')

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    db.init_app(app)
    metadata.init_app(app)

    app.register_blueprint(auth.blueprint)
    app.register_blueprint(books.blueprint)
    app.register_blueprint(feed.blueprint)
    app.register_blueprint(home.blueprint)
    app.register_blueprint(saml.blueprint)

    return app
Exemple #23
0
def __setup_db():
    """
    Setup the database and create a connection
    """
    with __flask_app.app_context():
        db.init_app(__flask_app)
        db.init_db()
    auth.register_user('root', 'root')
Exemple #24
0
def register_extensions(app):
    db.init_app(app)
    migrate.init_app(app, db)
    ma.init_app(app)
    <%= unless bare do %>
    bcrypt.init_app(app)
    jwt.init_app(app)
    <% end %>
def register_extensions(app):
    assets.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Exemple #26
0
def create_app():
    app = Flask(__name__)
    # existing code omitted

    import db
    db.init_app(app)

    return app
def configure_extensions(app, cli):
    """configure flask extensions
    """
    db.init_app(app)
    jwt.init_app(app)

    if cli is True:
        migrate.init_app(app, db)
Exemple #28
0
    def setUp(self):
        self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
        app.testing = True
        self.client = app.test_client()
        app.config['MIN_TRANSFER_AMOUNT'] = MIN_TRANSFER_AMOUNT
        app.config['MAX_WALLET_VALUE'] = MAX_WALLET_VALUE

        init_app(app)
Exemple #29
0
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    migrate.init_app(app, db)
    debug_tb.init_app(app)
    return None
def init(app):
    db.init_app(app)
    media.init_app(app)
    init_um(app)
    init_routes(app)
    init_uploads(app)
    robot.init_app(app)
    robot.logger = app.logger
    wapi.init_app(app)
def create_app():
    app = Flask(__name__)
    app.config.from_object('{{ cookiecutter.package_name}}.config.settings')

    db.init_app(app)
    api_v1.init_app(app)
    Alembic(app)

    return app
Exemple #32
0
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    flask_static_digest.init_app(app)
    return None
Exemple #33
0
def registerExtensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    cache.init_app(app)
    cors.init_app(app, supports_credentials=True)
    db.init_app(app)
    migrate.init_app(app)
    debug_toolbar.init_app(app)
    return None
Exemple #34
0
def register_extensions(app):
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Exemple #35
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
def configure_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Exemple #37
0
def create_app(test_config=None):
    # Create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(SECRET_KEY='dev',
                            DATABASE=os.path.join(app.instance_path,
                                                  local_db_name),
                            LOCALDATABASE=os.path.join(os.getcwd(),
                                                       local_db_name))

    if test_config is None:
        # Load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # Load the test config if passed in
        app.config.from_mapping(test_config)

    import db
    db.init_app(app)

    ############
    ###Routes###
    ############

    @app.route('/')
    def root():
        return "API Main.  Use */api/recommend/"

    @app.route('/api/recommend/', methods=['GET'])
    def recommend():
        # Set Defaults
        num_responses = 5

        if request.method == 'GET':
            if not 'search' in request.args:
                raise InvalidUsage(message="Search query not provided")
            if 'qty' in request.args:
                # print('number_responses', request.args['qty'])  # Debug
                num_responses = int(request.args['qty'])

        # Get indices of strain from KDTree model
        prediction_indices = predictor.predict('Glorious orange-red sativa',
                                               size=num_responses)
        # Query database with those indices
        prediction_data = db.query_database(prediction_indices.tolist())

        return prediction_data

    # Register error handler
    @app.errorhandler(InvalidUsage)
    def handle_invalid_usage(error):
        response = jsonify(error.to_dict())
        response.status_code = error.status_code
        return response

    return app
Exemple #38
0
def create_app(test_config=None, init=False, python_called=False):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    if python_called:
        import db
        import auth
        import entry
        import profile
    else:
        from . import db
        from . import auth
        from . import entry
        from . import profile

    db.init_app(app)

    if init:
        with app.app_context():
            db.init_db()
            db_instance = db.get_db()
            db_instance.execute(
                'INSERT INTO user (username, password, admin) VALUES (?, ?, ?)',
                ("*****@*****.**", generate_password_hash("admin"), 1))
            db_instance.commit()

    app.register_blueprint(auth.bp)
    app.register_blueprint(entry.bp)
    app.register_blueprint(profile.bp)
    app.add_url_rule('/', endpoint='index')

    return app
Exemple #39
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    debug_toolbar.init_app(app)
    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    security.init_app(app, user_datastore)
    migrate.init_app(app, db)
    return None
Exemple #40
0
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    webpack.init_app(app)
    return None
Exemple #41
0
def configure_extensions(app, cli):
    """configure flask extensions
    """
    db.init_app(app)
    jwt.init_app(app)
    CORS(app)

    if cli is True:
        migrate.init_app(app, db)

    sentry.init_app(app, dsn=app.config.get('SENTRY_DSN'))
Exemple #42
0
def init(app):
    api.init_app(app)
    db.init_app(app)
    media.init_app(app)
    login.init_app(app)
    login.login_view = '.login'

    @login.user_loader
    def load_user(id):
        return User.objects(id=id).first()

    init_uploads(app)
    init_routes(app)
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. {{cookiecutter.app_name}}.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)

    if cache:
        # initialize the cache
        cache.init_app(app)

    if debug_toolbar:
        # initialize the debug tool bar
        debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    if assets_env:
        assets_env.init_app(app)
        assets_loader = PythonAssetsLoader(assets)
        for name, bundle in assets_loader.load_bundles().items():
            assets_env.register(name, bundle)

    # register our blueprints
    main_controller.before_request(before_app_request)
    app.register_blueprint(main_controller)

    admin_controller.before_request(before_app_request)
    app.register_blueprint(admin_controller)

    file_controller.before_request(before_app_request)
    app.register_blueprint(file_controller)

    return app
Exemple #44
0
def register_extenstions(app):
    """
    Load flask extensions

    :param app: Flask application instance
    :type app: flask.app.Flask
    """

    # Database (Flask-SQLAlchemy)
    db.init_app(app)

    # Migrations
    migrate.init_app(app, db)

    # Flask Security
    datastore = SQLAlchemyUserDatastore(db, User, Role)
    security.init_app(app, datastore=datastore)
Exemple #45
0
def init(app):
    """ 初始化后台管理 """
    admin = Admin(
        name=BaseConfig.SITE_NAME,
        index_view=IndexView('仪表盘', menu_icon_value='diamond'),
        base_template='base.html',
    )
    admin.add_view(WebStaticAdmin(WebConfig.RELEASE_STATIC_FOLDER,
        'http://{{ cookiecutter.web_host }}/static/', name='文件', menu_icon_value='folder'))

    admin.init_app(app)
    db.init_app(app)
    um.init_app(app)
    init_uploads(app)

    with app.app_context():
        cm.init_admin(admin)
Exemple #46
0
def create_app(config=None):

  app = Flask(__name__)

  default_config = os.path.join(app.root_path, 'local_config.py')
  app.config.from_pyfile(default_config)

  if config:
    app.config.from_pyfile(config)

  blueprints = []

  db.init_app(app)

  admin_panel = register_admin_views(admin, blueprints)
  admin_panel.init_app(app)

  app = register_endpoints(app, blueprints)

  migrate.init_app(app, db)

  return app
Exemple #47
0
def create_app(config_object, env):
    '''An application factory, as explained here:
        http://flask.pocoo.org/docs/patterns/appfactories/

    :param config_object: The configuration object to use.
    :param env: A string, the current environment. Either "dev" or "prod"
    '''
    app = Flask(__name__)
    app.config.from_object(config_object)
    app.config['ENV'] = env
    # Initialize SQLAlchemy
    db.init_app(app)
    # Register asset bundles
    assets_env.init_app(app)
    assets_loader = PythonLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)
    # Register blueprints
    from {{cookiecutter.repo_name}}.modules import public, member
    app.register_blueprint(public.blueprint)
    app.register_blueprint(member.blueprint)

    return app
def app_factory(module_name, config):
    app = Flask(module_name)
    app.config.from_object(config)
    db.init_app(app)
    app.register_blueprint(api.api_app, url_prefix='/api')
    return app
from flask import Flask, Blueprint, flash, request, redirect, url_for, session, render_template
from flask.ext.sqlalchemy import SQLAlchemy
import config
from flask.ext.login import login_user, logout_user, login_required
from critiquebrainz.db import User

_name = "CritiqueBrainz"
_version = "0.1"

# app init
app = Flask(__name__)
app.config.from_object('critiquebrainz.config')

# db init
import db
db.init_app(app)

# login init
import login
login.init_app(app)

# oauth init
import oauth
oauth.init_app(app)

# musicbrainz init
import musicbrainz
musicbrainz.init_app(_name, _version)

# register uuid converter
from utils import UUIDConverter