__init__.py 文件源码

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

项目:wrath-ctf-framework 作者: WhiteHatCP 项目源码 文件源码
def create_app():
    app = flask.Flask(__name__)
    config_file = "./ctf.json"

    if 'CTF_CONFIG' in os.environ:
        config_file = os.environ['CTF_CONFIG']

    try:
        config = open(config_file, 'r')
        app.config.update(json.load(config))
    except IOError:
        raise IOError("The CTF configuration file could not be found")
    except ValueError:
        raise ValueError("The CTF configuration file was malformed")

    redis_url = app.config.get('REDIS_URL', 'redis://localhost')
    app.redis = redis.StrictRedis.from_url(redis_url)

    # Setup extensions
    ext.db.init_app(app)
    ext.csrf.init_app(app)

    @app.before_first_request
    def create_db():
        db.create_all()
        setup.build_challenges()

    @app.context_processor
    def inject_jinja_globals():
        """The authed flag should NOT be used to secure access control.

        The aim of the 'authed' global is simply better link rendering in
        templates.
        """
        return {'authed': 'key' in flask.session,
                'name': core.get_name()}

    def handle_error(exc):
        if not isinstance(exc, exceptions.HTTPException):
            exc = exceptions.InternalServerError()
        return flask.render_template('error.html', code=exc.code), exc.code

    for code in exceptions.default_exceptions.keys():
        app.register_error_handler(code, handle_error)

    app.register_blueprint(frontend.bp)
    app.register_blueprint(api.bp, url_prefix='/api')

    return app
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号