本文整理汇总了Python中flask_assets.Environment方法的典型用法代码示例。如果您正苦于以下问题:Python flask_assets.Environment方法的具体用法?Python flask_assets.Environment怎么用?Python flask_assets.Environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_assets
的用法示例。
在下文中一共展示了flask_assets.Environment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_app
# 需要导入模块: import flask_assets [as 别名]
# 或者: from flask_assets import Environment [as 别名]
def init_app(app):
webassets = Environment(app)
webassets.register('css_all', css_all)
webassets.register('js_all', js_all)
webassets.manifest = 'cache' if not app.debug else False
webassets.cache = not app.debug
webassets.debug = app.debug
示例2: init
# 需要导入模块: import flask_assets [as 别名]
# 或者: from flask_assets import Environment [as 别名]
def init(app) -> None:
"""
Bundle projects assets.
:param app: Main application instance
:type app: flask.Flask
"""
assets = Environment(app)
assets.auto_build = app.config.get('ASSETS_AUTO_BUILD', True)
files_to_watch = []
if 'COLLECT_STATIC_ROOT' in app.config:
assets.cache = app.config['COLLECT_STATIC_ROOT']
collect = Collect()
collect.init_app(app)
collect.collect()
app.static_folder = app.config['COLLECT_STATIC_ROOT']
for key in ['js', 'css']:
assets_key = '%s_ASSETS' % key.upper()
build_files = app.config[assets_key]
files_to_watch.extend(_get_files_for_settings(app, assets_key))
bundle = Bundle(*build_files,
output=app.config['%s_OUTPUT' % assets_key],
filters=app.config['%s_FILTERS' % assets_key]
)
assets.register('%s_all' % key, bundle)
app.logger.debug('Bundling files: %s%s',
os.linesep,
os.linesep.join(build_files))
app.assets = assets
app._base_files_to_watch = files_to_watch
app.logger.info('Base assets are collected successfully.')
示例3: init
# 需要导入模块: import flask_assets [as 别名]
# 或者: from flask_assets import Environment [as 别名]
def init(app):
assets = Environment(app)
js = Bundle(*app.config['JS_ASSETS'],
output=app.config['JS_ASSETS_OUTPUT'],
filters=app.config['JS_ASSETS_FILTERS'])
css = Bundle(*app.config['CSS_ASSETS'],
output=app.config['CSS_ASSETS_OUTPUT'],
filters=app.config['CSS_ASSETS_FILTERS'])
assets.register('js_all', js)
assets.register('css_all', css)
示例4: create_app
# 需要导入模块: import flask_assets [as 别名]
# 或者: from flask_assets import Environment [as 别名]
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# not using sqlalchemy event system, hence disabling it
config[config_name].init_app(app)
# Set up extensions
mail.init_app(app)
db.init_app(app)
login_manager.init_app(app)
csrf.init_app(app)
compress.init_app(app)
RQ(app)
# Register Jinja template functions
from .utils import register_template_utils
register_template_utils(app)
# Set up asset pipeline
assets_env = Environment(app)
dirs = ['assets/styles', 'assets/scripts']
for path in dirs:
assets_env.append_path(os.path.join(basedir, path))
assets_env.url_expire = True
assets_env.register('app_css', app_css)
assets_env.register('app_js', app_js)
assets_env.register('vendor_css', vendor_css)
assets_env.register('vendor_js', vendor_js)
# Configure SSL if platform supports it
if not app.debug and not app.testing and not app.config['SSL_DISABLE']:
from flask.ext.sslify import SSLify
SSLify(app)
# Create app blueprints
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
from .account import account as account_blueprint
app.register_blueprint(account_blueprint, url_prefix='/account')
from .admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')
from .club import club as club_blueprint
app.register_blueprint(club_blueprint, url_prefix='/club')
from .question import question as question_blueprint
app.register_blueprint(question_blueprint, url_prefix='/question')
from .category import category as category_blueprint
app.register_blueprint(category_blueprint, url_prefix='/category')
return app
示例5: create_app
# 需要导入模块: import flask_assets [as 别名]
# 或者: from flask_assets import Environment [as 别名]
def create_app(config):
app = Flask(__name__)
config_name = config
if not isinstance(config, str):
config_name = os.getenv('FLASK_CONFIG', 'default')
app.config.from_object(Config[config_name])
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# not using sqlalchemy event system, hence disabling it
Config[config_name].init_app(app)
# Set up extensions
mail.init_app(app)
db.init_app(app)
login_manager.init_app(app)
csrf.init_app(app)
compress.init_app(app)
RQ(app)
# Register Jinja template functions
from .utils import register_template_utils
register_template_utils(app)
# Set up asset pipeline
assets_env = Environment(app)
dirs = ['assets/styles', 'assets/scripts']
for path in dirs:
assets_env.append_path(os.path.join(basedir, path))
assets_env.url_expire = True
assets_env.register('app_css', app_css)
assets_env.register('app_js', app_js)
assets_env.register('vendor_css', vendor_css)
assets_env.register('vendor_js', vendor_js)
# Configure SSL if platform supports it
if not app.debug and not app.testing and not app.config['SSL_DISABLE']:
from flask_sslify import SSLify
SSLify(app)
# Create app blueprints
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
from .account import account as account_blueprint
app.register_blueprint(account_blueprint, url_prefix='/account')
from .admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')
return app