def create_app(): app.config['SQLALCHEMY_DATABASE_URI'] = database_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config.SWAGGER_UI_JSONEDITOR = True app.config.update(mail_settings) db.init_app(app) mail.init_app(app) # with app.app_context(): # db.create_all() blueprint = Blueprint('api', __name__, url_prefix='/doc') api.init_app(blueprint) api.add_namespace(books_ns) api.add_namespace(borrowers_ns) api.add_namespace(loans_ns) api.add_namespace(lists_ns) app.register_blueprint(blueprint) @app.route('/') def hello_world(): return 'Hello Rasengan' # init BackgroundScheduler job scheduler = BackgroundScheduler() scheduler.add_job(reminder_job, trigger='interval', days=1) scheduler.start() try: return app except: scheduler.shutdown()
def create_app(config_name): app = Flask(__name__, instance_relative_config=True) app.config.from_object(config[config_name]) # 加载普通配置 app.config.from_pyfile('config.py') # 加载私密配置 instance/config.py config[config_name].init_app(app) # 创建数据表 db.app = app db.init_app(app) db.create_all() if User.query.get(ADMIN[0]) is None: user = User() user.id = ADMIN[0] user.password = MD5Twice(ADMIN[1]) user.isAdmin = True user.nickname = '管理员' db.session.add(user) db.session.commit() from admin.admin import admin, init_login init_login(app) admin.init_app(app) api.decorators = [swagger_login] # swagger页面需要认证 api.init_app(app) app.session_interface = RedisSessionInterface() return app
def make_app(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) environment = os.environ.get("APPLICATION_ENV", "development") application = Flask(__name__) application.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get( 'DATABASE_URL') application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False application.app_context().push() # Configura as API's api.init_app(application) # inicia banco de dados init_db(application) # Configuração do Sentry sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"), integrations=[FlaskIntegration()], environment=environment) # Producer do Kafka logging.info("Conectando no Kafka: " + os.environ.get("KAFKA_BROKERS") + " / " + os.environ.get("KAFKA_SECURITY_PROTOCOL")) connect_producer( os.environ.get("KAFKA_BROKERS"), security_protocol=os.environ.get("KAFKA_SECURITY_PROTOCOL")) return application
def initialize_app(flask_app): logger.info("Configuring api server") blueprint = Blueprint("api", __name__, url_prefix="/api/v1") api.init_app(blueprint) api.add_namespace(kanban_namespace) api.add_namespace(issues_namespace) flask_app.register_blueprint(blueprint)
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) # initialize SQLAlchemy db.init_app(app) # prepare for db migration migrate = Migrate(app, db) # define hello world page @app.route('/') def hello_world(): return render_template('/index.html') @app.route('/aboutus') def about_us(): return render_template('/aboutus.html') @app.route('/contactus') def contact_us(): return render_template('/contactus.html') @app.route('/smartvenue') def smartventue(): return render_template('/smartvenue.html') return app
def create_app(config_filename=None): app = Flask(__name__) blueprint = Blueprint('api', __name__) api.init_app(blueprint) api.add_namespace(login, '/login') app.register_blueprint(blueprint) cors = CORS(app, resources={r"/*": {"origins": "*"}}) return app
def init_objects(app): from api import api api.init_app(app) api.app = app from service.mqttService import mqtt mqtt.init_app(app) mqtt.app = 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) redis_client.init_app(app) iface = app.config["IFACE"] my_ip4 = ni.ifaddresses(iface)[AF_INET][0]['addr'] my_ip6 = ni.ifaddresses(iface)[AF_INET6][0]['addr'] @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'GET': plot = get_flows_chart(my_ip4, my_ip6) return render_template('index.html', my_ip4=my_ip4, my_ip6=my_ip6, plot=plot) if request.form['submit'] == 'block': ip = request.form['ip'] port = request.form['port'] logger.debug("Block %s at port %s", ip, port) try: ipaddress.ip_address(ip) int(port) flash("Block {} at {}".format(ip, port), "warning") block_ip.delay(ip, port) except ValueError as err: flash("{}".format(err), "danger") logger.warning(err) if request.form['submit'] == 'redirect': src_ip = request.form['src_ip'] src_port = request.form['src_port'] dst_ip = request.form['dst_ip'] dst_port = request.form['dst_port'] logger.debug("Redirect %s:%s to %s:%s", src_ip, src_port, dst_ip, dst_port) try: ipaddress.ip_address(src_ip) int(src_port) ipaddress.ip_address(dst_ip) int(dst_port) flash( "Redirect {}:{} to {}:{}".format(src_ip, src_port, dst_ip, dst_port), "warning") except ValueError as err: flash("{}".format(err), "danger") logger.warning(err) return redirect(url_for('index')) return app
def create_app(): app = Flask(__name__) configure_app(app) api.init_app(app) migrate = Migrate() db.init_app(app) migrate = Migrate(app, db) 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 create_app(config_filename): #init flask app then return app = Flask(__name__) app.config.from_object(config_filename) from models import db db.init_app(app) from api import api api.init_app(app) return app
def create_app(environment): # Get the configuration class config_class = EnvironmentConfig.get(environment) # Create the app app = Flask(__name__) app.config.from_object(config_class) # Set up the logger Logger.set_up_app_loggers(app) # Enable Cross-Origin Resource Sharing (CORS) CORS(app, send_wildcard=True) with app.app_context(): # Initialize Plugins ##### DB Set up #### db.init_app(app) db_uri = app.config['SQLALCHEMY_DATABASE_URI'] if 'sqlite' in db_uri: db_svc = SQLiteDatabaseService(db) elif 'mysql' in db_uri: db_svc = MySQLDatabaseService(db) db_svc.set_charset(app.config['SQLALCHEMY_DATABASE_URI']) if config_class.SQLALCHEMY_DB_RESET: db_svc.reset() DataBaseSeed.seed() else: db_svc.create_all() flk_admin.init_app(app) if config_class.FLASK_ADMIN_ACTIVE: DBAdmin.create_admin_views(db) # Set up the database migration migrate.init_app(app, db) ##### End of DB Set up #### # Set up jwt manager jwt = JWTManager() jwt.init_app(app) # Setup the app schemas ma.init_app(app) # Set up the app namespaces api.init_app(app) api.update_description(app.config['ENV_NAME']) return app
def main(): app = Flask(__name__) #TODO: remove after frontend coder tested the api on localhost CORS(app, resources={r"/*": {"origins": "*"}}) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://zsqxmatch:[email protected]:3306/xmatch' api.init_app(app) db.init_app(app) host = 'localhost' if __env__ == 'prod': host = '0.0.0.0' app.run(debug=True, host=host)
def create_app(): # logger.info(f'Starting app in {APP_ENV} environment') app_ = Flask(__name__) app_.config.from_object('config') api.init_app(app_) app_.config['JWT_SECRET_KEY'] = 'jwt-secret-string' JWTManager(app_) @app_.route('/') def index(): return render_template('index.html') 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) logger.info(f'Config {config.as_dict()}') @app.route("/") def index(): return render_template('index.html') return app
def create_app(): app = Flask(__name__) app.config.from_envvar('FISBANG_SETTINGS') from models.user import User, Role from models.sensor import Sensor from models.device import Device, DeviceType from models.environment import Environment from models.project import Project bootstrap.init_app(app) db.init_app(app) user_datastore = SQLAlchemyUserDatastore(db, User, Role) security.init_app(app, user_datastore) nodb.init_app(app) from models.sensor_data import SensorData nodb.register([SensorData]) from homepage import homepage as homepage_blueprint app.register_blueprint(homepage_blueprint, url_prefix='/') from app import app as app_blueprint app.register_blueprint(app_blueprint, url_prefix='/app') from market import market as market_blueprint app.register_blueprint(market_blueprint, url_prefix='/market') from dashboard import dashboard as dashboard_blueprint app.register_blueprint(dashboard_blueprint, url_prefix='/dashboard') from api import api api.init_app(app) from services import mailing mailing.config(app.config.get('ADMINS', None)) @app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 @app.errorhandler(500) def internal_server_error(e): return render_template('500.html'), 500 return app
def setup_app(): db_uri = getenv( 'SQLALCHEMY_DATABASE_URI') # format: postgresql://user:pw@host:port/db if not db_uri: abort(401) app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = db_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False api.init_app(app) cache.init_app(app) db.init_app(app) return app
def initialize_app(app): initialize_db = configure_app(app) api.add_namespace(cloud_accounts_ns) api.add_namespace(cloud_providers_ns) api.add_namespace(customers_ns) api.add_namespace(users_ns) api.init_app(app) db.init_app(app) jwt = JWTManager(app) if initialize_db: reset_database(app)
def create_app(): LOGGER.info('Starting app in %s environment', config.APP_ENV) app = Flask(__name__) app.config.from_object('config') api.init_app(app) # initialize SQLAlchemy db.init_app(app) # define hello world page @app.route('/') def hello_world(): return 'Hello, World!' return app
def create_app(): app = Flask(__name__) app.config.from_object(Config) db.init_app(app) # blueprint register from api import api_bp app.register_blueprint(api_bp) from api import api api.init_app(app) return app
def setup_app(): app = Flask(__name__) if ENABLE_DB: db_uri = getenv('SQLALCHEMY_DATABASE_URI' ) # format: postgresql://user:pw@host:port/db if db_uri: app.config['SQLALCHEMY_DATABASE_URI'] = db_uri else: abort(401) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False with app.app_context(): api.init_app(app) return app
def make_app(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) environment = os.environ.get("APPLICATION_ENV", "development") application = Flask(__name__) api.init_app(application) sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"), integrations=[FlaskIntegration()], environment=environment) bus = make_consumers(application) bus.run() listen_kill_server(bus) return application
def main(): app = Flask(__name__) #TODO: remove after frontend coder tested the api on localhost CORS(app, resources={r"/*": {"origins": "*"}}) app.config['SESSION_TYPE'] = 'filesystem' app.config['SECRET_KEY'] = "secret key 4 prod Xmatch" Session(app) session.permanent = True app.permanent_session_lifetime = timedelta(minutes=5) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://zsqxmatch:[email protected]:3306/xmatch' api.init_app(app) db.init_app(app) host = 'localhost' if __env__ == 'prod': host = '0.0.0.0' app.run(debug=True, host=host)
def initialize_app(flask_app): """ Initialize the application API. :param Flask flask_app: The Flask application to configure. """ # Create a blueprint to house the API, swagger can be reached from /api # and each of the models from /api/[model] blueprint = Blueprint('api', __name__, url_prefix='/api') api.init_app(blueprint) # Configure namespaces per model on the API. api.add_namespace(noms_namespace) flask_app.register_blueprint(blueprint) db.init_app(flask_app) with flask_app.app_context(): db.create_all()
def create_app(): app = Flask(__name__) app.config.from_pyfile('app.cfg', True) db.init_app(app) api.init_app(app) cron.init_app(app) with app.app_context(): from routes import routes app.register_blueprint(routes) init_dash(app) db.create_all() cron.start() return app
def create_app(): logger.debug('Making an app') app = Flask(__name__) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@192.168.1.239:5432/melth_db' logger.debug('Initialisation of the DB') from models import db db.init_app(app) with app.app_context(): db.create_all() logger.debug('Initialisation of the marshmallow') from models import ma ma.init_app(app) logger.debug('Initialisation of the api') from api import api api.init_app(app) return app
def initialize_app(flask_app): configure_app(flask_app) # Get arguments from cli parser = argparse.ArgumentParser(description='PiServer') parser.add_argument("--init", default=False, help="This initialise the database") args = parser.parse_args() init_db = args.init # Initialise DB if not init_db: initialise_db(app, False) else: initialise_db(app, True) # Initialise JWT initialise_jwt(app) # Initialise API api.init_app(app) initialise_routes(api)
def create_app(config_filename): app = Flask(__name__) app.config.from_object(config_filename) CORS(app, resources={ r"/*": {"origins": ['http://127.0.0.1:8080', 'http://localhost:8080']}}) from api import api api.init_app(app) from model import db db.init_app(app) # from jwt_ext import jwt jwt = JWTManager() jwt.init_app(app) from mail import mail mail.init_app(app) return app
def register_extensions(app: Flask) -> None: db.init_app(app) api.init_app(app) qrcode.init_app(app)
def create_app(): log.info(f'Starting app in {config.APP_ENV} environment') app = Flask(__name__) app.config.from_object('config') api.init_app(app) return app
from logging import Logger from flask import Flask from flask_cors import CORS from flask_jwt_simple import JWTManager from werkzeug.middleware.proxy_fix import ProxyFix from api import api from utils import Config, is_dev app = Flask(__name__) app.config.from_object(Config) # Proxy middleware # swagger fix app.wsgi_app = ProxyFix(app.wsgi_app) jwt = JWTManager(app) CORS(app) logger = app.logger logger.setLevel(Config.LOG_LEVEL) logger.propagate = False api.init_app(app) if __name__ == "__main__": app.run(host=Config.HOST, port=Config.PORT, debug=Config.DEBUG)
def init_app(app): db.init_app(app) migrate.init_app(app, db) api.init_app(app)
from flask import Flask from flask import make_response, send_file from models import db from api import api, Tasks, Users, Token app = Flask(__name__, static_url_path="") app.config.from_pyfile("settings.cfg") db.init_app(app) api.init_app(app) api.prefix = api.app.config["BASE_API_URL"] api.add_resource(Tasks, "/tasks/<string:todo_id>") api.add_resource(Users, "/users", "/users/<int:id>") api.add_resource(Token, "/token") @app.route("/") def index(): if app.config["DEBUG"]: return make_response(open("../client/dist/index.html").read()) else: return send_file(open("static/index.html").read())