def initialize_extensions(app): """Helper functions""" api.init_app(app) db.init_app(app) mail.init_app(app) migrate.init_app(app, db, directory='migrations') jwt.init_app(app)
def register_extensions(app): api.init_app(app) db.init_app(app) jwt = JWTManager(app) @app.route("/") def serve(): return send_from_directory(app.static_folder, "index.html") @app.route("/<path>") def static_proxy(path): """static folder serve""" file_name = path.split("/")[-1] dir_name = os.path.join(app.static_folder, "/".join(path.split("/")[:-1])) return send_from_directory(dir_name, file_name) @jwt.token_in_blacklist_loader def check_if_token_in_blacklist(decrypted_token): jti = decrypted_token['jti'] return RevokedToken.is_jti_blacklisted(jti) @app.errorhandler(404) def not_found(e): if request.path.startswith("/api/"): return jsonify(status="error", message="{}".format(e)), 404 return send_from_directory(app.static_folder, "index.html") @app.errorhandler(405) def not_found(e): if request.path.startswith("/api/"): return jsonify(status="error", message="{}".format(e)), 405 return send_from_directory(app.static_folder, "index.html")
def configure_extensions(app, cli): """configure flask extensions """ db.init_app(app) jwt.init_app(app) if cli is True: migrate.init_app(app, db)
def create_app(): app = Flask(__name__) app.config.from_object(BaseConfig()) # initialize SqlAlchemy with flask config db.init_app(app) return app
def register_extensions(app): """Register Flask extensions.""" # Register database and models with app.app_context(): db.init_app(app) migrate.init_app(app, db) # Register JWT helper jwt.init_app(app)
def initialize_extensions(app): """Helper functions""" api.init_app(app) db.init_app(app) jwt.init_app(app) mail.init_app(app) migrate.init_app(app, db, directory="migrations") @jwt.token_in_blacklist_loader def check_if_token_in_blacklist(decrypted_token): """Checking if token is blacklisted""" jti = decrypted_token["jti"] return JWTToken.is_jti_blacklisted(jti)
def extensions(app): """ Register 0 or more extenstions (mutates the app thats passed in) :param app: Flask application instance :return: None """ db.init_app(app) with app.app_context(): db.create_all() return None
def register_extensions(app: Flask): """Register Flask extensions.""" # Register database and models with app.app_context(): db.init_app(app) migrate.init_app(app, db) # Register JWT token auth jwt.init_app(app) # Registering application encryption bcrypt.init_app(app)
def create_app(config=BaseConfig()): app = Flask(__name__) CORS(app) app.config.from_object(config) # initialize SqlAlchemy with flask config db.init_app(app) # this will add /graphql and /graphiql endpoints to app app.add_url_rule("/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True)) return app
def _db(): """Create and configure a new db instance for pytest-flask-sqlalchemy.""" db_fd, db_path = tempfile.mkstemp() app = create_app() app.config["TESTING"] = True app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["DATABASE"] = db_path app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" with app.app_context(): db.init_app(app) db.create_all() yield db os.close(db_fd) os.unlink(db_path)
def app(): """Create and configure a new app instance for tests.""" # create a temp file to isolate the db for each test db_fd, db_path = tempfile.mkstemp() app = create_app() app.config["TESTING"] = True app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["DATABASE"] = db_path app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" # create the db and load test data with app.app_context(): db.init_app(app) db.create_all() yield app # close and remove the temporary db os.close(db_fd) os.unlink(db_path)
def create_app(config_class: type = DevelopmentConfig, init_scheduler: bool = True) -> Flask: app: Flask = Flask(__name__) CORS(app) app.config.from_object(config_class) api: Api = Api(app) create_routing(api) db.init_app(app) db.app = app migrate.init_app(app, db) jwt.init_app(app) if init_scheduler: # For testing purpose, scheduler is turned off scheduler.init_app(app) scheduler.start() return app
def register_extensions(app): cors.init_app(app) db.init_app(app) ma.init_app(app)
def register_extensions(app): db.init_app(app) CORS(app, resources={r"/*": {"origins": "*"}})
def register_extensions(app): db.init_app(app) migrate.init_app(app, db) mail.init_app(app) avatars.init_app(app) limiter.init_app(app)
def register_extensions(app): db.app = app db.init_app(app) migrate.init_app(app, db, render_as_batch=True)
# security/__init__.py from flask import url_for, Blueprint, flash, redirect from flask_restful import Api from flask_security import logout_user from backend import server from backend.extensions import admin, db from backend.base_model import BaseModel from .route_builder import build_routes from .utilities import ExtendedLoginForm # Configure app settings import backend.core.config_runner db.init_app(server) BaseModel.set_session(db.session) import backend.core.security security_bp = Blueprint('user_bp', __name__) security_api = Api(security_bp) @server.route("/logout") def logout(): logout_user() flash("Logged out!") return redirect(url_for("frontend_bp.serve_pages", page="index"))