本文整理汇总了Python中flask_assets.Environment.append_path方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.append_path方法的具体用法?Python Environment.append_path怎么用?Python Environment.append_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_assets.Environment
的用法示例。
在下文中一共展示了Environment.append_path方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import append_path [as 别名]
def install(cls, app):
"""Install the extension into the application."""
Environment.resolver_class = InvenioResolver
env = Environment(app)
env.url = "{0}/{1}/".format(app.static_url_path,
app.config["ASSETS_BUNDLES_DIR"])
env.directory = os.path.join(app.static_folder,
app.config["ASSETS_BUNDLES_DIR"])
env.append_path(app.static_folder)
env.auto_build = app.config.get("ASSETS_AUTO_BUILD", True)
# The filters less and requirejs don't have the same behaviour by
# default. Make sure we are respecting that.
app.config.setdefault("LESS_RUN_IN_DEBUG", True)
app.config.setdefault("REQUIREJS_RUN_IN_DEBUG", False)
# Fixing some paths as we forced the output directory with the
# .directory
app.config.setdefault("REQUIREJS_BASEURL", app.static_folder)
requirejs_config = os.path.join(env.directory,
app.config["REQUIREJS_CONFIG"])
if not os.path.exists(requirejs_config):
app.config["REQUIREJS_CONFIG"] = os.path.relpath(
os.path.join(app.static_folder,
app.config["REQUIREJS_CONFIG"]),
env.directory)
app.jinja_env.add_extension(BundleExtension)
app.context_processor(BundleExtension.inject)
示例2: register_assets
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import append_path [as 别名]
def register_assets(app):
assets = Environment(app)
assets.url = app.static_url_path
assets.directory = app.static_folder
assets.append_path('assets')
scss = Bundle('scss/main.scss', filters='pyscss', output='main.css', depends=('scss/*.scss'))
assets.register('scss_all', scss)
示例3: create_app
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import append_path [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 .participant import participant as participant_blueprint
app.register_blueprint(participant_blueprint, url_prefix='/participant')
return app
示例4: SQLAlchemy
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import append_path [as 别名]
'sni/templates/podcast/']),
])
app.jinja_loader = my_loader
db = SQLAlchemy(app)
Markdown(app, extensions=['footnotes'])
pages = FlatPages(app)
manager = Manager(app)
# Scss
assets = Environment(app)
assets.url_expire = True
assets.auto_build = True
assets.append_path('sni/assets')
assets.cache = 'sni/assets/.webassets-cache'
scss = Bundle('scss/__main__.scss', filters='pyscss', output='css/main.css',
depends=['scss/*.scss'])
assets.register('scss_all', scss)
assets.debug = False
app.config['ASSETS_DEBUG'] = False
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
if not app.debug:
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('tmp/snilog.csv',
示例5: TestUrlAndDirectory
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import append_path [as 别名]
class TestUrlAndDirectory(TempEnvironmentHelper):
"""By default, the 'url' and 'directory' settings of webassets are
not used in Flask-Assets; that is, the values are automatically
handled based on the configuration of the Flask app and the modules
used.
The user can disable the automatic handling by setting these values
if he needs to for some reason.
Let's test the different scenarios to ensure everything works.
"""
def setup(self):
TempEnvironmentHelper.setup(self)
self.app = Flask(__name__, static_path='/app_static')
from tests import test_module
if not Blueprint:
self.module = Module(test_module.__name__, name='module',
static_path='/mod_static')
self.app.register_module(self.module)
else:
self.blueprint = Blueprint('module', test_module.__name__,
static_url_path='/mod_static',
static_folder='static')
self.app.register_blueprint(self.blueprint)
self.env = Environment(self.app)
def test_config_values_not_set_by_default(self):
assert not 'directory' in self.env.config
assert not 'url' in self.env.config
assert_raises(KeyError, self.env.config.__getitem__, 'directory')
assert_raises(KeyError, self.env.config.__getitem__, 'url')
def test_directory_auto(self):
"""Test how we resolve file references through the Flask static
system by default (if no custom 'env.directory' etc. values
have been configured manually).
"""
assert not 'directory' in self.env.config
root = self.app.root_path
assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
# Modules prefixes in paths are handled specifically.
assert get_all_bundle_files(Bundle('module/bar'), self.env) == [root + '/test_module/static/bar']
# Prefixes that aren't valid module names are just considered
# subfolders of the main app.
assert get_all_bundle_files(Bundle('nomodule/bar'), self.env) == [root + '/static/nomodule/bar']
# In case the name of a app-level subfolder conflicts with a
# module name, you can always use this hack:
assert get_all_bundle_files(Bundle('./module/bar'), self.env) == [root + '/static/module/bar']
# Custom static folder
self.app.static_folder = '/'
assert get_all_bundle_files(Bundle('foo'), self.env) == ['/foo']
def test_url_auto(self):
"""Test how urls are generated via the Flask static system
by default (if no custom 'env.url' etc. values have been
configured manually).
"""
assert not 'url' in self.env.config
assert Bundle('foo', env=self.env).urls() == ['/app_static/foo']
# Urls for files that point to a module use that module's url prefix.
assert Bundle('module/bar', env=self.env).urls() == ['/mod_static/bar']
# Try with a prefix that's not actually a valid module
assert Bundle('nomodule/bar', env=self.env).urls() == ['/app_static/nomodule/bar']
# [Regression] Ensure that any request context we may have added
# to the stack has been removed.
from flask import _request_ctx_stack
assert _request_ctx_stack.top is None
def test_custom_load_path(self):
"""A custom load_path is configured - this will affect how
we deal with source files.
"""
self.env.append_path(self.tempdir, '/custom/')
self.create_files(['foo', 'module/bar'])
assert get_all_bundle_files(Bundle('foo'), self.env) == [self.path('foo')]
# We do not recognize references to modules.
assert get_all_bundle_files(Bundle('module/bar'), self.env) == [self.path('module/bar')]
assert Bundle('foo', env=self.env).urls() == ['/custom/foo']
assert Bundle('module/bar', env=self.env).urls() == ['/custom/module/bar']
# [Regression] With a load path configured, generating output
# urls still works, and it still uses the flask system.
self.env.debug = False
self.env.url_expire = False
assert Bundle('foo', output='out', env=self.env).urls() == ['/app_static/out']
def test_custom_directory_and_url(self):
"""Custom directory/url are configured - this will affect how
we deal with output files."""
# Create source source file, make it findable (by default,
# static_folder) is set to a fixed subfolder of the test dir (why?)
self.create_files({'a': ''})
self.app.static_folder = self.tempdir
#.........这里部分代码省略.........