__init__.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:afl-mothership 作者: afl-mothership 项目源码 文件源码
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. mothership.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    @app.before_first_request
    def _run_on_start():
        init_db()

    csrf = CsrfProtect(app)

    @app.template_filter('datetime')
    def datetimeformat(value, format='%d/%m/%y %H:%M %p'):
        return datetime.datetime.utcfromtimestamp(value).strftime(format)

    app.config.from_object(object_name)

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    # debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(campaigns)
    app.register_blueprint(graphs)
    app.register_blueprint(fuzzers)
    csrf.exempt(fuzzers)

    try:
        os.mkdir(app.config['DATA_DIRECTORY'])
    except FileExistsError:
        pass

    return app
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号