예제 #1
0
def create_app(configuration=Config):
    app = Flask(__name__)

    from app.models import db, login_manager, migrate

    app.config.from_object(configuration)
    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    login_manager.login_view = "route_blueprint.login"

    from app.routes import route_blueprint

    app.register_blueprint(route_blueprint)

    from app.auth import auth_blueprint

    app.register_blueprint(auth_blueprint, url_prefix="/auth/")

    from app.reports import reports_bp

    app.register_blueprint(reports_bp, url_prefix="/reports/")

    from app.candidates import candidates_bp

    app.register_blueprint(candidates_bp, url_prefix="/candidates/")

    return app
예제 #2
0
def create_app(config=None):
    app = Flask(__name__)

    if config is None:
        config = os.path.join(
            app.root_path, os.environ.get('FLASK_APPLICATION_SETTINGS')
        )

    app.config.from_pyfile(config)
    app.secret_key = app.config['SECRET_KEY']

    db.init_app(app)
    migrate.init_app(app, db)
    sec_state = security.init_app(app)
    admin.init_app(app)

    admin.add_view(UserAdmin(User, db.session, category="Accounts"))
    admin.add_view(RoleAdmin(Role, db.session, category="Accounts"))

    @sec_state.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
        )

    app.register_blueprint(cart)

    return app
예제 #3
0
def create_app():
    app = Flask(__name__, instance_relative_config=True, static_url_path='')

    app.config.from_mapping(
        SECRET_KEY=os.environ.get('SECRET_KEY') or 'secret',
        SQLALCHEMY_DATABASE_URI=os.environ.get('DATABASE_URL')
        or 'sqlite:///' + os.path.join(app.instance_path, 'app.db'),
        SQLALCHEMY_TRACK_MODIFICATIONS=False,
    )

    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    CORS(app)

    from flask_sslify import SSLify
    if 'DYNO' in os.environ:  # only trigger SSLify if app is running on Heroku
        sslify = SSLify(app)

    from app.models import db, migrate
    db.init_app(app)
    migrate.init_app(app, db)

    from app.cli import create_admin
    app.cli.add_command(create_admin)

    from app.api import api
    app.register_blueprint(api)

    return app
예제 #4
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config[app.env or 'development'])
    db.init_app(app)
    api.init_app(app)
    migrate.init_app(app)
    return app
예제 #5
0
def create_app(config_class=Config):
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(config_class)
    app.config.from_pyfile('config.py', silent=True)

    from app.models import db, ma, migrate
    db.init_app(app)
    ma.init_app(app)
    migrate.init_app(app, db)
    from app.resources import api
    api.init_app(app)
    CORS(app)
    return app
예제 #6
0
def create_app():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = SECRET_KEY  # For flash messages

    # Configure the database
    app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URI
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    db.init_app(app)
    migrate.init_app(app, db)

    # Configure routes - register each route we have with the app
    app.register_blueprint(home_routes)
    app.register_blueprint(model_routes)
    return app
예제 #7
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    from app.models import db, migrate, ma
    db.init_app(app)
    migrate.init_app(app, db)
    ma.init_app(app)

    from app.routes import api, cors
    cors.init_app(app)
    app.register_blueprint(api)

    return app
def create_app():
    app = Flask(__name__)

    # load_dotenv()

    app.config['SQLALCHEMY_DATABASE_URI'] = "URL"

    # db = SQLAlchemy(app)
    # migrate = Migrate(app, db)

    db.init_app(app)
    migrate.init_app(app, db)

    app.register_blueprint(stat_routes)
    return app
예제 #9
0
def create_app():
    app = Flask(__name__)
    app.static_folder = 'static' # for css

    app.config["SECRET_KEY"] = SECRET_KEY
    app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL
    db.init_app(app)
    migrate.init_app(app, db)

    app.register_blueprint(home_routes)
    app.register_blueprint(book_routes)
    app.register_blueprint(twitter_routes)
    app.register_blueprint(stats_routes)
    app.register_blueprint(admin_routes)
    
    return app
예제 #10
0
def create_app():
    app = Flask(__name__)
    #CORS(app)

    #app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////mnt/c/Github/MediCabinet/data-engineering/database.sqlite3"
    # configure the database
    app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    db.init_app(app)
    migrate.init_app(app, db)

    # configure routes
    app.register_blueprint(flask_app)
    app.register_blueprint(recommend_routes)

    return app
예제 #11
0
def create_app():
    """
    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. app.settings.ProdConfig
    """
    env = os.getenv('FLASK_ENV')
    if env == 'development':
        env = 'Dev'
    elif env == 'production':
        env = 'Prod'
    else:
        env = 'Test'

    app = Flask(__name__)

    app.config.from_object("app.settings.%sConfig" % env)

    # commands
    configure_commands(app)

    # cache
    cache.init_app(app)

    # debug tool bar
    debug_toolbar.init_app(app)

    # SQLAlchemy
    db.init_app(app)
    migrate.init_app(app, db)
    engine = create_engine(app.config.get('SQLALCHEMY_DATABASE_URI'))
    if not database_exists(engine.url):
        create_database(engine.url)

    # login
    login_manager.init_app(app)

    configure_global_interceptor(app)
    # register blueprints
    app.register_blueprint(main)

    return app
예제 #12
0
def register_extensions(app):
    """Register extensions for Flask app

    Args:
        app (Flask): Flask app to register for
    """
    db.init_app(app)
    migrate.init_app(app, db)
    csrf_protect.init_app(app)
    ma.init_app(app)
    user_manager = UserManager(
        app, db, User, UserInvitationClass=UserInvitation
    )

    assets = Environment(app)
    assets.url = app.static_url_path
    scss = Bundle('scss/site.scss', filters='libsass', output='site.css')
    assets.register('scss_all', scss)
예제 #13
0
def create_app():
    """creates flask application and returns it"""
    app = Flask(__name__,
                template_folder='app/templates',
                static_folder='app/static')
    app.register_blueprint(bp)

    app.config.from_object(os.environ['APP_SETTINGS'])

    # setting the level of socketio logs to ERROR to reduce spammy messages in flask server output
    logger = logging.getLogger('werkzeug')
    logger.setLevel(logging.ERROR)

    db.init_app(app)
    migrate.init_app(app, db)
    socketio.init_app(app)

    return app
예제 #14
0
파일: app.py 프로젝트: filchyboy/flask_work
def create_app():
    '''
    Initiates routes & database for the website app.
    '''
    app = Flask(__name__)

    app.config["SECRET_KEY"] = SECRET_KEY # allows us to use flash messaging
    app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

    db.init_app(app)
    migrate.init_app(app, db)

    #app.register_blueprint(home_routes)
    #app.register_blueprint(twitter_routes)
    #app.register_blueprint(admin_routes)
    #app.register_blueprint(stats_routes)

    return app
예제 #15
0
def create_app():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = SECRET_KEY  # required for flash messaging

    # configure the database:
    app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL
    app.config[
        "SQLALCHEMY_TRACK_MODIFICATIONS"] = False  # suppress warning messages
    db.init_app(app)
    migrate.init_app(app, db)

    # configure routes:
    app.register_blueprint(home_routes)
    app.register_blueprint(book_routes)
    app.register_blueprint(tweets_routes)
    app.register_blueprint(admin_routes)
    app.register_blueprint(stats_routes)

    return app
예제 #16
0
def create_app(configuration=Config):
    """Flask App Instance"""
    # Create app and load configuration
    app = Flask(__name__)
    app.config.from_object(configuration)

    # Import extensions
    from app.models import db, csrf, migrate

    # Register extensions
    db.init_app(app)
    csrf.init_app(app)
    migrate.init_app(app, db)

    # Import blueprints
    from app.views.base import base

    # Register blueprints
    app.register_blueprint(base)
    return app
예제 #17
0
def create_app():

    app = Flask(__name__)
    CORS(app, resources={r"/products/*": {"origins": "*"}})

    # get the pg database url from heroku envenviroment
    DATABASE_URL = getenv("DATABASE_URL")

    # configure the database:
    app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URL
    app.config[
        "SQLALCHEMY_TRACK_MODIFICATIONS"] = False  # suppress warning messages

    db.init_app(app)
    migrate.init_app(app, db)

    app.register_blueprint(home_routes)
    app.register_blueprint(web_routes)
    app.register_blueprint(admin_routes)

    return app
예제 #18
0
def register_extensions(app):
    """Register extensions for Flask app

    Args:
        app (Flask): Flask app to register for
    """
    db.init_app(app)
    migrate.init_app(app, db)
    ma.init_app(app)
    mail.init_app(app)
    csrf_protect.init_app(app)
    user_manager = CustomUserManager(app, db, User)

    @app.context_processor
    def context_processor():
        return dict(user_manager=user_manager)

    assets = Environment(app)
    assets.url = app.static_url_path
    scss = Bundle('scss/site.scss', filters='libsass', output='site.css')
    assets.register('scss_all', scss)

    db.create_all(app=app)
예제 #19
0
def create_app(config_name):
    """
    Sets up the Flask app instance with settings etc.
    Uses the "Application Factory"-pattern here, which is described
    in detail inside the Flask docs:
    https://flask.palletsprojects.com/en/1.1.x/patterns/appfactories/
    """
    app = Flask(__name__)

    # Flask extension for handling Cross Origin Resource Sharing (CORS)
    CORS(app, resources={r"/api/*": {"origins": "*"}})

    # This makes sure that the operations are active in the right app context
    # in detail inside the Flask docs:
    # https://flask.palletsprojects.com/en/1.1.x/appcontext/
    with app.app_context():
        # loads the setting from the config.py
        app.config.from_object(config.app_config[config_name])
        app.config.from_pyfile('config.py')
        app.config[
            'SQLALCHEMY_DATABASE_URI'] = config.Config.SQLALCHEMY_DATABASE_URI
        app.config[
            'SQLALCHEMY_TRACK_MODIFICATIONS'] = config.Config.SQLALCHEMY_TRACK_MODIFICATIONS
        # defines the API ressource URLs
        from app.routes.api import TranslationRessource

        api = Api(app)
        api.add_resource(TranslationRessource, '/api/translations/',
                         '/api/translations/<string:uid>')

        # initiates the database and the migration
        from app.models import db, migrate
        db.init_app(app)
        migrate.init_app(app, db)

    return app
예제 #20
0
def create_app(test_config=None) -> Flask:
    app = Flask("chandeblog", instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY="dev",
        SQLALCHEMY_DATABASE_URI="sqlite:////{}/db.sqlite3".format(
            app.instance_path),
        SQLALCHEMY_TRACK_MODIFICATIONS=False,
        UPLOAD_FOLDER=os.path.join(BASE_DIR, "media"),
        MAX_CONTENT_LENGTH=16 * 1000 * 1000,
        ORIGINS=[],
    )

    if test_config is None:
        app.config.from_pyfile("config.py", silent=True)
    else:
        app.config.from_mapping(test_config)

    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    CORS(app, supports_credentials=True, origins=app.config.get("ORIGINS"))

    from app.models import db, migrate
    db.init_app(app)
    migrate.init_app(app, db)

    from app.views import bp, init_app
    app.register_blueprint(bp)
    init_app(app)

    from app.utils import init_app
    init_app(app)

    return app
예제 #21
0
def init_app(app):
    db.init_app(app)
    migrate.init_app(app, db)
예제 #22
0
recaptchaPri = getenv('RECAPTCHA_PRIVATE_KEY')
# Config Activation
app.config['SECRET_KEY'] = secretKey
app.config['SQLALCHEMY_DATABASE_URI'] = dbUri
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = sqlTrackModifcation
app.config['USE_SESSION_FOR_NEXT'] = useSessionNext
app.config['RECAPTCHA_PUBLIC_KEY'] = recaptchaPub
app.config['RECAPTCHA_PRIVATE_KEY'] = recaptchaPri

# Sql Alchemy Activation
db.init_app(app)

# Flask-Login Activation
loginManager.init_app(app)

# Flask-Migrate Activation
migrate.init_app(app, db)

# Bcrypt Activation
bcrypt.init_app(app)

# Register Blueprints
app.register_blueprint(view)

# CSRF
csrf.init_app(app)

if __name__ == '__main__':
    app.jinja_env.cache = {}
    app.run()