def create_app(conf): from views.scc_view import scc from views.main_view import main from views.cxw_view import cxw # from views.api_view import api # view_list = [scc, main, api] view_list = [scc, main, cxw] app = Flask(__name__) # to apply config to app,must before init of SQLAlchemy and LoginManager app.config.from_object(conf) # from app.views.api_view import ToolsApi, ArticleApi, ApiRoute, ApiComment, CaptchaApi api = Api(app) api.add_resource(ToolsApi, '/api/tools/uuid/', endpoint='tool') api.add_resource(CaptchaApi, '/api/tools/captcha', endpoint='captcha') api.add_resource(ArticleApi, '/api/article/uuid/<uuid>', endpoint='article') api.add_resource(ApiComment, '/api/comment/id/<id>', endpoint='comment') api.add_resource(ApiRoute, '/api/token/', endpoint='route') db.init_app(app) # http://blog.csdn.net/yannanxiu/article/details/53426359 # http://www.pythondoc.com/flask-sqlalchemy/api.html#flask.ext.sqlalchemy.SQLAlchemy.init_app # http://librelist.com/browser/flask/2010/8/30/sqlalchemy-init-app-problem/ db.app = app # do not use setup_app() lm.session_protection = 'strong' lm.login_view = "main.main_login" lm.refresh_view = "main.main_login" lm.needs_refresh_message = u"To protect your account, please re-authenticate to access this page." lm.needs_refresh_message_category = "info" # lm callback @lm.user_loader def load_user(uid): return Login.get(uid) # auth callback @auth.verify_password def verify_password(username_or_token, password): user = Login.verify_auth_token(username_or_token) if not user: user = Login.query.filter_by(user=username_or_token).first() if not user or not user.verify_password(password): return False g.user_ = user # distinguish with flask-login user return True lm.init_app(app) mail.init_app(app) for view in view_list: # register static fold path to blueprint view.static_folder = conf.static_path view.template_folder = conf.template_path(postfix=view.name) # register blueprint to app app.register_blueprint(view) return app
def startdb(self): logging.info("Initializing database: Host=%s User=%s", config.dbhost, config.dbuser) with app.app_context(): db.init_app(app) db.create_all(app=app) InitRoles()
def create_app(conf): # set app config app = Flask(__name__, static_folder='static', template_folder='templates') app.config.from_object(conf) # ApiDoc(app) # auto register blueprint services = [] pathlist = os.listdir(conf.BASE_PATH) for path in pathlist: if os.path.isdir(os.path.join(conf.BASE_PATH, path)): subpath_list = os.listdir(os.path.join(conf.BASE_PATH, path)) if 'views.pyc' in subpath_list or 'views.py' in subpath_list: services.append({'package': path, 'blueprint': path + '_bp'}) print('BLUEPRINT: [%s] loading completed !' % (path)) for service in services: module = importlib.import_module('.views', package=service['package']) app.register_blueprint(getattr(module, service['blueprint'])) # init sqlalchemy db.init_app(app) # init flask-redis if os.path.exists(os.path.join(conf.BASE_PATH, 'redis_ext')): from redis_ext import R R.init_app(app) print('REDIS: Init done!') else: print('REDIS: Init failed!') if os.path.exists(os.path.join(conf.BASE_PATH, 'celery_ext')): from celery_ext import cly cly.init_app(app) cly.conf.update(app.config) print('CELERY: Init done!') else: print('CELERY: Init failed!') # if os.path.exists(os.path.join(conf.BASE_PATH, 'sch')): # from sch import scheduler # config.JOBS.append({ # 'id': 'createschuler_job', # 'func': hello_world, # 'args': None, # 'trigger': 'interval', # 'seconds': 5}) # scheduler.init_app(app) # fix nginx proxy app.wsgi_app = ProxyFix(app.wsgi_app) # Cross domain request allowed CORS(app, resources={r"/*": {"origins": "*"}}) return app
def create_app(enviroment): app = Flask(__name__) app.config.from_object(enviroment) with app.app_context(): db.init_app(app) db.create_all() return app
def create_app(config_filename): app = Flask(__name__) app.config.from_object(config_filename) CORS(app) api = Api(app) api.add_resource(Book, '/books', '/books/<int:id>') from models.database import db db.init_app(app) return app
def create_app_db(db, test_config=""): # create and configure the app app = Flask(__name__, instance_relative_config=True) # load the instance config, if it exists, when not testing #app.config.from_pyfile('config.py', silent=True) if not test_config: app.config.from_object("config.DefaultConfig") else: app.config.from_object(test_config) #mail = Mail(app) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError: pass #format database connection uri db_user = app.config['DB_USER'] db_password = app.config['DB_PASSWORD'] db_url = app.config['DB_URL'] db_name = app.config['DB_NAME'] #connect to database using flask's sql alchemy #sqlalchemyuri = f'postgresql://{db_user}:{db_password}@{db_url}/{db_name}' sqlalchemyuri = 'postgresql://' + db_user + ':' + db_password + '@' + db_url + '/' + db_name app.config['SQLALCHEMY_DATABASE_URI'] = sqlalchemyuri #bind datbase to this app db.init_app(app) app.app_context().push() #initialize flask user for authentication #user_manager = UserManager(app, db, UserModel) #register_form=nameRegisterForm) user_manager = NameUserManager(app, db, UserModel) #register_form=nameRegisterForm) #initialize database #try: # db.drop_all() #except: # print("couldn't drop") # pass db.create_all() #addTransaction(db, 0) #add routes app.register_blueprint(login_routes) return app
def cria_app(config=None): app = Flask(__name__) if config: app.config.from_pyfile(config) #db.create_all() #from models import db db.init_app(app) from incluir_produto import User #db.create_all() #with app.app_context(): # db.create_all() app.register_blueprint(cadastro_produtos) app.register_blueprint(todos_produtos) app.register_blueprint(lista_produto) return app
def create_app(): app = Flask(__name__) app.config.from_object('config.Config') app.register_blueprint(expense_routes, url_prefix="/expense") app.register_blueprint(category_routes, url_prefix="/category") db.init_app(app) # Ensure FOREIGN KEY for sqlite3 if 'sqlite' in app.config['SQLALCHEMY_DATABASE_URI']: def _fk_pragma_on_connect(db, conn_record): # noqa db.execute('pragma foreign_keys=ON') with app.app_context(): event.listen(db.engine, 'connect', _fk_pragma_on_connect) return app
def initialize_app(app): from models.database import db db.init_app(app) app.app_context().push() ProPublica.initialize(os.environ['PROPUBLICA_API_KEY']) EventRegistry2.initialize(os.environ['EVENT_REGISTRY_API_KEY']) GoogleCivicInformation.initialize( os.environ['GOOGLE_CIVIC_INFORMATION_API_KEY']) pp = ProPublica() er = EventRegistry2() gpo = GovernmentPublishingOffice(114) cog = CongressGov() dhg = DocsHouseGov() sg = SenateGov() pf = Politifact() gci = GoogleCivicInformation() Committee.initialize_datasources(pp) Congress.initialize_datasources(pp, er, gpo, pf, dhg, sg, gci) Congressperson.initialize_datasources(pp, er, gpo, pf, None) global cg cg = Congress.get_or_create(115) Congressperson.initialize_datasources(pp, er, gpo, pf, cg) # Create a TwilioCapability object with our Twilio API credentials global twilio_phone_number twilio_phone_number = os.environ.get('TWILIO_PHONE_NUMBER', None) if os.environ.get('TWILIO_AUTH_TOKEN', None) is not None: # Allow our users to make outgoing calls with Twilio Client account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['TWILIO_AUTH_TOKEN'] global capability capability = TwilioCapability(account_sid, auth_token) capability.allow_client_outgoing(os.environ['TWIML_APP_SID'])
import os from otapi import otapi # import Flask from flask import Flask, Blueprint from models.database import db app = Flask(__name__) app.config.from_object('config') db.init_app(app) # Set REST API blueprints from resources import * app.register_blueprint(api_account.mod_account, url_prefix='/api') app.register_blueprint(api_asset.mod_asset, url_prefix='/api') app.register_blueprint(api_nym.mod_nym, url_prefix='/api') app.register_blueprint(api_server.mod_server, url_prefix='/api') app.register_blueprint(api_wallet.mod_wallet, url_prefix='/api') app.register_blueprint(api_transaction.mod_transaction, url_prefix='/api') # Set Controllers blueprints from controllers import * app.register_blueprint(mod_c_index) app.register_blueprint(mod_c_account) app.register_blueprint(mod_c_nym) # Set Facade blueprint from facade import * app.register_blueprint(mod_facade)
def create_app(self): app = create_app(env="TEST") db.init_app(app) return app