本文整理匯總了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