当前位置: 首页>>代码示例>>Python>>正文


Python whitenoise.WhiteNoise方法代码示例

本文整理汇总了Python中whitenoise.WhiteNoise方法的典型用法代码示例。如果您正苦于以下问题:Python whitenoise.WhiteNoise方法的具体用法?Python whitenoise.WhiteNoise怎么用?Python whitenoise.WhiteNoise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在whitenoise的用法示例。


在下文中一共展示了whitenoise.WhiteNoise方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: static

# 需要导入模块: import whitenoise [as 别名]
# 或者: from whitenoise import WhiteNoise [as 别名]
def static(root: str, **kwargs) -> WSGIApp:
    """Return a WSGI app that serves static files under the given directory.

    Powered by [WhiteNoise](http://whitenoise.evans.io).

    [config-attrs]: http://whitenoise.evans.io/en/stable/base.html#configuration-attributes

    # Parameters
    root (str):
        the path to a directory from where static files should be served.
        If the directory does not exist, no files will be served.
    **kwargs (any):
        keyword arguments passed to the WhiteNoise constructor. See also [Configuration attributes (WhiteNoise docs)][config-attrs].

    # Returns
    app (callable): a WhiteNoise WSGI app.
    """
    if exists(root):
        kwargs["root"] = root
    return WhiteNoise(empty_wsgi_app(), **kwargs) 
开发者ID:bocadilloproject,项目名称:bocadillo,代码行数:22,代码来源:staticfiles.py

示例2: init_app

# 需要导入模块: import whitenoise [as 别名]
# 或者: from whitenoise import WhiteNoise [as 别名]
def init_app(self, app):
        """Initializes the Flask application with Common."""
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        if 'common' in app.extensions:
            raise RuntimeError("Flask-Common extension already initialized")

        app.extensions['common'] = self
        self.app = app

        if 'COMMON_FILESERVER_DISABLED' not in app.config:
            with app.test_request_context():

                # Configure WhiteNoise.
                app.wsgi_app = WhiteNoise(app.wsgi_app, root=url_for('static', filename='')[1:])

        self.cache = Cache(app, config={'CACHE_TYPE': app.config.get("COMMON_CACHE_TYPE", 'simple')})

        @app.before_request
        def before_request_callback():
            request.start_time = maya.now()

        @app.after_request
        def after_request_callback(response):
            if 'COMMON_POWERED_BY_DISABLED' not in current_app.config:
                response.headers['X-Powered-By'] = 'Flask'
            if 'COMMON_PROCESSED_TIME_DISABLED' not in current_app.config:
                response.headers['X-Processed-Time'] = maya.now().epoch - request.start_time.epoch
            return response

        @app.route('/favicon.ico')
        def favicon():
            return redirect(url_for('static', filename='favicon.ico'), code=301) 
开发者ID:schedutron,项目名称:flask-common,代码行数:36,代码来源:flask_common.py

示例3: create_app

# 需要导入模块: import whitenoise [as 别名]
# 或者: from whitenoise import WhiteNoise [as 别名]
def create_app(*, testing=False):
    app = Flask(__name__)
    app.config["SECRET_KEY"] = SECRET_KEY

    if testing:
        app.config["TESTING"] = True
        database_uri = "sqlite:///:memory:"
        app.config["RQ_ASYNC"] = False
    else:
        database_uri = DATABASE_URI

    app.config["SQLALCHEMY_DATABASE_URI"] = database_uri
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    db.init_app(app)
    migrate.init_app(app, db)

    app.config["RQ_REDIS_URL"] = REDIS_URI
    app.config["RQ_QUEUES"] = ["default"]
    rq.init_app(app)

    login_manager.init_app(app)
    talisman.init_app(app)

    app.register_error_handler(NotAuthorized, handle_http_error)
    app.register_error_handler(OAuthError, handle_oauth_error)
    app.register_error_handler(ValidationError, handle_validation_error)

    app.register_blueprint(events_bp, cli_group=None)
    app.register_blueprint(healthcheck_bp)
    app.register_blueprint(github_bp, url_prefix="/github", cli_group=None)
    app.register_blueprint(slack_bp, url_prefix="/slack")
    app.register_blueprint(twitter_bp, cli_group=None)
    app.register_blueprint(web_bp)

    app.wsgi_app = WhiteNoise(
        app.wsgi_app, root="busy_beaver/static/", prefix="assets/"
    )

    @app.before_request
    def add_internal_dictionary():
        """Keep request specific data in `_internal` dictionary"""
        if not getattr(request, "_internal", None):
            request._internal = {}

    return app 
开发者ID:busy-beaver-dev,项目名称:busy-beaver,代码行数:47,代码来源:app.py


注:本文中的whitenoise.WhiteNoise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。