def create_app(): app = Flask(__name__) app.config['UPLOAD_DIR'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'upload') app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024 app.config['DB_DIRECTORY'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database') app.config['DB_7Z_PATH'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database', 'permission_db.7z') app.config['DB_PATH'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database', 'permission_db.db') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DB_PATH'] app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Establish the database connection. db.init_app(app) # Create the upload directory (if not already existing). if not os.path.exists(app.config['UPLOAD_DIR']): os.makedirs(app.config['UPLOAD_DIR']) # Check if the database file is already extracted from the archive, otherwise extract it. if not os.path.isfile(app.config['DB_PATH']): instruction = '7z x "{0}" -o"{1}"'.format(app.config['DB_7Z_PATH'], app.config['DB_DIRECTORY']) subprocess.run(instruction, shell=True) return app
def create_app(): app = Flask(__name__) app.config.from_pyfile('config.py') db.init_app(app) app.register_blueprint(short_blueprint) return app
def run_jobs(): """send sms messages due for current hour""" with app.app_context(): db.init_app(app) now = datetime.now() print("Current Hour:", now.hour) jobs_due = Job.query.filter_by( time=str(now.hour) + ':00').all() # TODO filter out inactive after testing is done # jobs_due = session.query(Job).filter_by(time=str(now.hour)+':00').options(joinedload('*')).all() print(jobs_due) for job in jobs_due: print("User:"******"User Phone:", job.phone, "User Msg:", job.msg_txt, "Status:", job.active) if job.active: job_id = job.id to = job.phone body = job.msg_txt send_sms(to, body, job_id) # print(to, body, job_id) print("Sending:", job.phone, job.msg_txt, job.id) # send_sms(job.phone, job.msg_txt, job.id) db.session.commit()
def app(request): """Session-wide test `Flask` application.""" settings_override = { 'TESTING': True, 'SQLALCHEMY_DATABASE_URI': TEST_DATABASE_URI, #'SQLALCHEMY_TRACK_MODIFICATIONS' : False, } app = create_app(__name__, settings_override) # Establish an application context before running the tests. ctx = app.app_context() ctx.push() print("DB Fixture!") """Session-wide test database.""" _db.init_app(app) _db.create_all() #db.create_all() def teardown(): _db.drop_all() ctx.pop() os.unlink(TESTDB_PATH) request.addfinalizer(teardown) return app
def create_app(config): app = Flask(__name__) CORS(app) app.config.from_object(config) # confi ps gress api.init_app(app) db.init_app(app) return app
def create_app(config_name): app = Flask(__name__, instance_relative_config=1) app.config.from_object(config_name) app.config.from_pyfile("config.py") from model import db db.init_app(app) from utilities import cache cache.init_app(app) from admin import admin admin.init_app(app) from security import security security.init_app(app) from main import main as main_blueprint app.register_blueprint(main_blueprint) return app
def create_app(platform): app = Flask(__name__) app.config.from_object(app_config[platform]) db.init_app(app) app.register_blueprint(harvester_blueprint, url_prefix='/harvester/') return app
def create_app(): app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get("FLASK_SECRET_KEY", "abcdef") db.init_app(app) with app.test_request_context(): db.create_all() return app
def create_app(): app = Flask(__name__) # 设置环境变量之类的东西 app.env = os.getenv("FLASK_ENV") app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("SQLALCHEMY_DATABASE_URI") # 数据库连接配置 app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY") app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(hours=24) app.config["PROPAGATE_EXCEPTIONS"] = True # 注册蓝图 app.register_blueprint(api) # 数据库连接相关 db.init_app(app) # jwt相关 jwt.init_app(app) # redis相关 if not redisInit(): raise Exception("Redis连接失败") # 创建表 with app.app_context(): db.create_all() db.session.commit() # 推送app上下文 app.app_context().push() return app
def connect_to_db(app): """Connect the database to our Flask app.""" # Configure to use our PstgreSQL database app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///commuknitty' db.app = app db.init_app(app)
def create_app(): app = Flask(__name__, static_folder='static') CORS(app) app.config.from_object("config") db.init_app(app) app.register_blueprint(api_1_0.bp, url_prefix='/api/1_0') return app
def connect_to_db(app): """Connect the database to our Flask app.""" # Configure to use postgresql database app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://coreyshott@localhost:5432/contributions" db.app = app db.init_app(app)
def connect_to_db(app): """Connecting the database to our Flask Application""" app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testdb' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app)
def init(configfile): app.config.from_pyfile('openmoves.cfg.default', silent=False) if configfile: if not os.path.exists(configfile): with open(configfile, 'w') as f: initialize_config(f) print("created %s" % configfile) app.config.from_pyfile(configfile, silent=False) assert app.config['SECRET_KEY'] SESSION_VERSION = 1 app.config['SECRET_KEY'] = "%s-%d" % (app.config['SECRET_KEY'], SESSION_VERSION) assert 'SQLALCHEMY_TRACK_MODIFICATIONS' not in app.config app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) with app.app_context(): if db.engine.name == 'sqlite': db.create_all() Bootstrap(app) app_bcrypt.init_app(app) login_manager.init_app(app) login_manager.login_view = "login" return app
def main(): app = Flask(__name__) app.config.from_envvar('OSWBLP_SETTINGS') app.register_blueprint(views) db.init_app(app) bcrypt.init_app(app) login_manager.init_app(app) app.run(host='0.0.0.0')
def create_flask_app(): app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///seq.db' app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False db.init_app(app) app.app_context().push() app.url_map.strict_slashes = False return app
def create_app(): app = Flask(__name__) configer.init_app(app) intercept.init_app(app) db.init_app(app) bp.init_app(app) return app
def connect_to_db(app, database_URI): """Connect the database to Flask app.""" app.config['SQLALCHEMY_DATABASE_URI'] = database_URI app.config['SQLALCHEMY_ECHO'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app)
def setUp(self): self.app = app.test_client() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' app.config['TESTING'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app) db.create_all()
def create_app(): application = Flask(__name__) application.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_URI application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.TRACK_MOD application.config['SECRET_KEY'] = config.SECRET_KEY db.init_app(application) ma.init_app(application) CORS(application) return application
def connect_to_test_db(app): """Connect the database to our Flask app.""" # Configure to use our database. app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///testdb' app.config['SQLALCHEMY_ECHO'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app)
def connect_to_db(app): """Connect the database to our Flask app""" app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testdb' app.config['TESTING'] = True app.config['SQLALCHEMY_ECHO'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app)
def create_app(config_filename): app = Flask(__name__) app.config.from_object(config_filename) app.register_blueprint(api_blueprint, url_prefix='/api/v1') db.init_app(app) return app
def create_app(): app = Flask(__name__) app.config['DEBUG'] = True app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///database.db" db.init_app(app) app.register_blueprint(login_blueprint) app.register_blueprint(profile_blueprint) app.secret_key = 'terrible secret' return app
def create_app(config_name): app.config.from_object(config[config_name]) from model import db db.init_app(app) login_manager.init_app(app) from views import main app.register_blueprint(main) return app
def create_app(self): self.app = create_app(PresentConfig) self.client = self.app.test_client() with self.app.app_context(): db.init_app(self.app) redis_cache.init_app(self.app) db.create_all() db.session.commit() return self.app
def connect_to_db(app): """Connect the database to the Flask app.""" # Configure to use the PstgreSQL database. app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///habot' app.config['SQLALCHEMY_ECHO'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app)
def create_app(): app = Flask(__name__) app.config.from_object('config') from model import db db.init_app(app) setup_views(app) return app
def create_app(self): application = Flask(__name__) application.config['TESTING'] = True # Empty SQLite URI points to in-memory database application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(application) return application
def setUp(self): """Set up database for testing purposes""" print "Setting up test database" self.app = app.test_client() app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///testdb' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app) db.create_all()
def run_site(self): import logging log = logging.getLogger("werkzeug") log.setLevel(logging.ERROR) app.register_blueprint(views.blog) db.init_app(app) webbrowser.open("http://localhost:5000/welcome") print(f"hosting {self.blog_name} on http://localhost:5000/ !") app.run()
def create_app(config_filename): app.config.from_object(config_filename) global t if t == 0: app.register_blueprint(api_bp, url_prefix='/api') t = 1 if config_filename != TestingConfig: db.init_app(app) redis_cache.init_app(app) return app
def create_app(): logger.info(f"Starting app in {config.APP_ENV} environment") app = Flask(__name__) app.config.from_object("config") api.init_app(app) db.init_app(app) return app
def setUp(self): """Set up database for testing purposes""" print "Setting up test database" self.app = app.test_client() app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///testdb' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app) db.create_all()
def setUp(self): """Stuff to do before every test.""" app.config['TESTING'] = True app.config['SECRET_KEY'] = os.environ['APP_SECRET'] app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) self.client = app.test_client() add_user_session(self) connect_to_db(app, "postgresql:///koi")
def init_db(): # set application configuration variables application.config['SQLALCHEMY_DATABASE_URI'] = environ['SQLALCHEMY_DATABASE_URI'] application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True # required to use Flask sessions and the debug toolbar application.secret_key = environ['FLASK_SECRET_KEY'] # assign database to Flask application db.app = application db.init_app(application)
def setUp(self): """ Setup a testing only database """ self.app = app.test_client() app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testingdb' db.app = app db.init_app(app) db.create_all() seed_db()
def setUp(self): """Set up database for testing purposes""" self.app = app.test_client() app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app) db.create_all() print "setup ran" # include for test_login() self._add_user()
def create_app(config_object): _app = Flask(__name__) _app.register_blueprint(helloworld.blueprint) db.init_app(_app) _app.config.from_object(config_object) override_env_name = 'FLASK_SEED_CONFIG' if _app.config.from_envvar(override_env_name, silent=True): path = os.environ[override_env_name] print 'Overriding config by environment variable: %s = %s' % (override_env_name, path) return _app
def register(app): if not hasattr(app, 'extensions'): app.extensions = {} if not hasattr(app.extensions, 'sqlalchemy'): db.init_app(app) security.init_app(app) @app.context_processor def security_context_processor(): return export_processor() app.register_blueprint(security_page)
def setUp(self): self.db_fd, self.db_filename = tempfile.mkstemp() app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////" + self.db_filename app.config["TESTING"] = True app.testing = True app.config["WTF_CSRF_ENABLED"] = False self.test_client = app.test_client() db.app = app db.init_app(app) with app.app_context(): db.create_all() seed.load_users() seed.load_listings() seed.load_messages()
def create_app(conf): # init app = Flask(__name__) app.config.from_pyfile(conf) # connect model to app db.init_app(app) with app.app_context(): db.create_all() # secure it SSLify(app) # register blueprints app.register_blueprint(api,url_prefix='/api/v1') app.register_blueprint(site,url_prefix='') return app
def setUp(self): self.db_fd, self.db_filename = tempfile.mkstemp() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////' + self.db_filename app.config['TESTING'] = True app.testing = True app.config['WTF_CSRF_ENABLED'] = False self.test_client = app.test_client() db.app = app db.init_app(app) with app.app_context(): db.create_all() seed.load_categories() seed.load_providers() seed.load_venues() seed.load_experiences()
def setUp(self): """ Setup a testing only database """ self.app = app.test_client() app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testingdb' db.app = app db.init_app(app) db.create_all() seed_db() u = User(first_name='Jane', last_name='Smith', email='*****@*****.**', username='******', password='******') db.session.add(u) db.session.commit() self.login('jsmith', 'test')
def create_app(): app = Flask(__name__) app.secret_key = SECRET_KEY app.config.update({ 'SQLALCHEMY_DATABASE_URI': SQLALCHEMY_DATABASE_URI, 'SQLALCHEMY_ECHO': SQLALCHEMY_ECHO, 'SQLALCHEMY_TRACK_MODIFICATIONS': True }) from model import db from .views import init_app as viewinit from .admin import admin db.init_app(app) viewinit(app) admin.init_app(app) login_manager.init_app(app) return app
def setUp(self): self.app = app.test_client() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' app.config['TESTING'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.app = app db.init_app(app) db.create_all() generate_example_schools() generate_example_users() generate_example_school_lists() # initiate session with self.app as c: with c.session_transaction() as sess: sess['user_id'] = '1'
def create_app(config_object): _app = Flask(__name__) for (name, bp) in blueprints.blueprints.iteritems(): print 'load %s blueprint' % name _app.register_blueprint(bp.blueprint) db.init_app(_app) principal.principal.init_app(_app) login.login_manager.init_app(_app) _app.config.from_object(config_object) override_env_name = 'FLASK_SEED_CONFIG' if _app.config.from_envvar(override_env_name, silent=True): path = os.environ[override_env_name] print 'Overriding config by environment variable: %s = %s' % (override_env_name, path) return _app
def connect_to_db(app, db, db_name): """Connect the database to Flask app.""" # Configure to use SQLite database app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_name db.app = app db.init_app(app) with app.app_context(): # http://stackoverflow.com/questions/19437883/when-scattering-flask-models-runtimeerror-application-not-registered-on-db-w # if in reseed mode, delete database so can be reseeded. if len(argv) > 1: script, mode = argv if mode == "reseed": os.remove(db_name) # if database doesn't exist yet, creates database if os.path.isfile(db_name) != True: db.create_all() logging.info("New database called '%s' created" % db_name) logging.info("Connected to %s" % db_name) return app
def register(app): if not hasattr(app, 'extensions'): app.extensions = {} if not hasattr(app.extensions, 'sqlalchemy'): db.init_app(app) admin.init_app(app)
def create_app(config={'MONGODB_SETTINGS': {'DB': "assignment"}}): app = Flask(__name__) app.config["MONGODB_SETTINGS"] = config['MONGODB_SETTINGS'] app.register_blueprint(api) db.init_app(app) return app
from flask import Flask, render_template from model import db, Cooperative app = Flask(__name__) app.config.from_pyfile("app_config.py") db.init_app(app) @app.route('/') def hello_world(): coops = Cooperative.query.filter(Cooperative.geo_raw_data != None).all() return render_template('index.html', cooperatives=coops) @app.route('/view_coop/<int:coop_id>') def view_coop(coop_id): return render_template('view_coop.html', coop=Cooperative.query.get_or_404(coop_id)) if __name__ == '__main__': app.run()
def register(app): if not hasattr(app, 'extensions'): app.extensions = {} if not hasattr(app.extensions, 'sqlalchemy'): db.init_app(app) app.register_blueprint(blog_page)
def connect_to_db(app): """Connect the database to our Flask app.""" # Configure to use PostgreSQL database app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///examplerecipes' db.app = app db.init_app(app)