Skip to content

Instantly share code, notes, and snippets.

@javamo
Last active November 9, 2017 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javamo/52b104d6fba89cf1c6509f391ae50f39 to your computer and use it in GitHub Desktop.
Save javamo/52b104d6fba89cf1c6509f391ae50f39 to your computer and use it in GitHub Desktop.
app/__init__.py
from os import getenv
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from .config import config
db = SQLAlchemy()
def create_app(config_name=None):
""" Create app.
"""
app = init_and_config_app(config_name)
app = add_plugins(app)
from .core import core as core_blueprint
app.register_blueprint(core_blueprint)
return app
def init_and_config_app(config_name):
""" Config app.
"""
app = Flask(__name__)
config_name = config_name or getenv("FLASK_CONFIG", "default")
app.config.from_object(config[config_name])
return app
def add_plugins(app):
""" Add plugins.
"""
db.init_app(app)
return app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment