Python flask_wtf.csrf 模块,CsrfProtect() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用flask_wtf.csrf.CsrfProtect()

项目: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