def create_app(): # App Initialization app = Flask(__name__, instance_relative_config=True) # Configuration Settings Config.init_app(app) # Pluggable Flask Extension db.init_app(app) ma.init_app(app) Migrate(app, db) sess.init_app(app) jwt.init_app(app) # Import Models from thinkbox.models import tokenmodels from thinkbox.models import uploadmodels from thinkbox.models import usermodels # Blueprints from thinkbox.auth import auth from thinkbox.dashboard import dash from thinkbox.analytics import ana from thinkbox.sklearnmodels import skmodels # Register Blueprints app.register_blueprint(auth, url_prefix="/auth") app.register_blueprint(dash, url_prefix="/dash") app.register_blueprint(ana, url_prefix="/dash/analytics") app.register_blueprint(skmodels, url_prefix="/dash/models") return app
def create_app(): app = Flask(__name__) CORS(app) config.init_app(app) database.init_app(app) migration.init_app(app) views.init_app(app) return app
def create_app(): app = Flask(__name__) app.config.from_object(config) config.init_app(app) from models import db db.app = app db.init_app(app) # scheduler.init_app(app) return app
def init_app(app): with app.app_context(): config.init_app(app) models.init_app(app) routes.init_app(app) services.init_app(app) # -- <testing user> ----------------------------------------------- admin_user = services.user_service.getByUsername('admin') if admin_user is None: services.user_service.insert('admin', 'admin') # -- </testing user> ---------------------------------------------- app.run(debug=True, port=3000)
def create_app(): app = Flask(__name__) config.init_app(app) {%- if sqlal %} db.init_app(app) migrate.init_app(app) auth.init_app(app) admin.init_app(app) # toolbar.init_app(app) {%- endif %} # here we invoke each extension's init_app function cli.init_app(app) site.init_app(app) hooks.init_app(app) return app
def create_app(): """flask application generator :return: flask application """ app = Flask(__name__) config.init_app(app) db.init_app(app) Swagger(app) with app.app_context(): """ application blueprints """ from server.api_1_0.views import api as api_blueprint app.register_blueprint(api_blueprint, url_prefix='/api/v1') return app
def create_app(): """ :return: flask application flask application generator """ current_dir = os.path.abspath(os.path.dirname(__file__)) template_folder = os.path.join(current_dir, 'templates') app = Flask(__name__, template_folder=template_folder) config.init_app(app) db.init_app(app) admin.init_app(app) """ application blueprints """ from example.main import main as main_blueprint app.register_blueprint(main_blueprint) return app
def prepare_main_app(args): """ Prepare Foris main application - i.e. apply CLI arguments, mount applications, install hooks and middleware etc... :param args: arguments received from ArgumentParser.parse_args(). :return: bottle.app() for Foris """ app = init_default_app() # basic and bottle settings template_dir = os.path.join(BASE_DIR, "templates") bottle.TEMPLATE_PATH.append(template_dir) logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING) # mount apps import config import wizard app.mount("/config", config.init_app()) app.mount("/wizard", wizard.init_app()) if args.debug: # "about:config" is available only in debug mode import uci # must be mounted before wrapping the app with middleware app.mount("/uci", uci.app) if args.noauth: logger.warning("authentication disabled") app.config["no_auth"] = True # set custom app attributes for main app and all mounted apps init_foris_app(app, None) for route in app.routes: if route.config.get("mountpoint"): mounted = route.config['mountpoint.target'] prefix = route.config['mountpoint.prefix'] init_foris_app(mounted, prefix) if args.nucipath: client.StaticNetconfConnection.set_bin_path(args.nucipath) # load Foris plugins before applying Bottle plugins to app loader = ForisPluginLoader(app) loader.autoload_plugins() # read language saved in Uci lang = read_uci_lang(DEFAULT_LANGUAGE) # i18n middleware if lang not in translations: lang = DEFAULT_LANGUAGE app = I18NMiddleware(app, I18NPlugin(domain="messages", lang_code=lang, default=DEFAULT_LANGUAGE, locale_dir=os.path.join(BASE_DIR, "locale"))) # logging middleware for all mounted apps app = ReportingMiddleware(app, sensitive_params=("key", "pass", "*password*")) app.install_dump_route(bottle.app()) if args.debug: # for nice debugging and profiling, try importing FireLogger support try: from firepython.middleware import FirePythonWSGI app = FirePythonWSGI(app) except ImportError: FirePythonWSGI = None # session middleware (note: session.auto does not work within Bottle) session_options = { 'session.type': 'file', 'session.data_dir': '/tmp/beaker/data', 'session.lock_dir': '/tmp/beaker/lock', 'session.cookie_expires': True, 'session.timeout': 900, 'session.auto': True, 'session.httponly': True, } app = SessionMiddleware(app, session_options) return app
#!/usr/bin/env python # -*- coding: utf-8 -*- # .. from flask import Flask from flask_script import Manager from flask_migrate import ( Migrate, MigrateCommand, ) # ... import config from models import db app = Flask(__name__) # config config.init_app(app) # migrate migrate = Migrate(app, db) # manager manager = Manager(app) manager.add_command('db', MigrateCommand) # ... if __name__ == '__main__': manager.run()
from flask import Flask, g, jsonify, request, json, send_file from flask_oidc import OpenIDConnect from flask_cors import CORS, cross_origin # from entities.request import Request from dataaccess.requestsDataAccess import RequestDataAccess from utils.jsonClassEncoder import JsonClassEncoder from config import init_app from utils.util import cors_preflight import os from datetime import datetime, timedelta import glob # configuration DEBUG = True app = init_app() requestDataAccess = RequestDataAccess() jsonClassEncoder = JsonClassEncoder() oidc = OpenIDConnect(app) @app.route('/') def home(): if oidc.user_loggedin: return ("Hello,%s" % oidc.user_getfield('email')) else: return 'Welcome, please <a href="/dashboard">Login</a>'
def prepare_main_app(args): """ Prepare Foris main application - i.e. apply CLI arguments, mount applications, install hooks and middleware etc... :param args: arguments received from ArgumentParser.parse_args(). :return: bottle.app() for Foris """ app = init_default_app() # basic and bottle settings template_dir = os.path.join(BASE_DIR, "templates") bottle.TEMPLATE_PATH.append(template_dir) logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING) # mount apps import config import wizard app.mount("/config", config.init_app()) app.mount("/wizard", wizard.init_app()) if args.debug: # "about:config" is available only in debug mode import uci # must be mounted before wrapping the app with middleware app.mount("/uci", uci.app) if args.noauth: logger.warning("authentication disabled") app.config["no_auth"] = True # set custom app attributes for main app and all mounted apps init_foris_app(app, None) for route in app.routes: if route.config.get("mountpoint"): mounted = route.config['mountpoint.target'] prefix = route.config['mountpoint.prefix'] init_foris_app(mounted, prefix) if args.nucipath: client.StaticNetconfConnection.set_bin_path(args.nucipath) # load Foris plugins before applying Bottle plugins to app loader = ForisPluginLoader(app) loader.autoload_plugins() # read language saved in Uci lang = read_uci_lang(DEFAULT_LANGUAGE) # i18n middleware if lang not in translations: lang = DEFAULT_LANGUAGE app = I18NMiddleware(app, I18NPlugin(domain="messages", lang_code=lang, default=DEFAULT_LANGUAGE, locale_dir=os.path.join(BASE_DIR, "locale"))) # logging middleware for all mounted apps app = ReportingMiddleware(app, sensitive_params=("key", "pass", "*password*")) app.install_dump_route(bottle.app()) if args.debug: # for nice debugging and profiling, try importing FireLogger support try: from firepython.middleware import FirePythonWSGI app = FirePythonWSGI(app) except ImportError: FirePythonWSGI = None # session middleware (note: session.auto does not work within Bottle) session_options = { 'session.type': 'file', 'session.data_dir': '/tmp/beaker/data', 'session.lock_dir': '/tmp/beaker/lock', 'session.cookie_expires': True, 'session.timeout': 900, 'session.auto': True, 'session.httponly': True, } app = SessionMiddleware(app, session_options) return app
from config import init_app from api import * app, server_info_dict = init_app("dev") app.register_blueprint(my_api) if __name__ == "__main__": app.run(host=server_info_dict["host"], port=server_info_dict["port"], use_reloader=False)
def create_app(): app = Flask(__name__) config.init_app(app) return app
import argparse import time import sys from config import init_app if (__name__ == '__main__'): # 멀티 테넌시 & 환경 옵션 mode = 'cli' env = 'dev' # 어플리케이션 객체 로드 및 실행 init_app(env, mode)
from flask import Flask, render_template, abort from flask_yarn import Yarn from config import init_app from models import db, Video, Up app = Flask(__name__) init_app(app) yarn = Yarn(app) db.app = app db.init_app(app) @app.route('/') def index(): return render_template('index.html', search={ 'token': '123456', 'placeholder': '加油哦' }, videos=Video.query.all()) @app.route('/video/av<int:vid>/') def video(vid): _video = Video.query.filter_by(vid=vid).first() if _video is None: return abort(404) _video.play += 1 db.session.commit() _up = Up.query.filter_by(uid=_video.uid).first() return render_template('video.html',
import argparse import time import sys import os # 멀티 테넌시 & 환경 옵션 mode = 'cli' env = 'dev' unittest = True import sys, os cur_path = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, cur_path + '/../') # 어플리케이션 객체 로드 및 실행 from config import init_app init_app(env, mode, unittest)