本文整理汇总了Python中flask_compress.Compress方法的典型用法代码示例。如果您正苦于以下问题:Python flask_compress.Compress方法的具体用法?Python flask_compress.Compress怎么用?Python flask_compress.Compress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_compress
的用法示例。
在下文中一共展示了flask_compress.Compress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
# 需要导入模块: import flask_compress [as 别名]
# 或者: from flask_compress import Compress [as 别名]
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev',
)
# http://flask.pocoo.org/docs/1.0/config/#configuring-from-files
app.config.from_object('scrapydweb.default_settings')
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
@app.route('/hello')
def hello():
return 'Hello, World!'
handle_db(app)
handle_route(app)
handle_template_context(app)
# @app.errorhandler(404)
# def handle_error(error):
# return ('Nothing Found', 404)
# http://flask.pocoo.org/docs/1.0/patterns/errorpages/
app.register_error_handler(500, internal_server_error)
# https://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_filters.html#other-useful-filters
# https://stackoverflow.com/questions/12791216/how-do-i-use-regular-expressions-in-jinja2
# https://www.michaelcho.me/article/custom-jinja-template-filters-in-flask
# http://flask.pocoo.org/docs/1.0/api/#flask.Flask.template_filter
@app.template_filter()
def regex_replace(s, find, replace):
return re.sub(find, replace, s)
app.jinja_env.variable_start_string = '{{ '
app.jinja_env.variable_end_string = ' }}'
compress = Compress()
compress.init_app(app)
app.logger.setLevel(logging.DEBUG)
return app