def create_app():
app = Flask(__name__)
app.config.from_object(config_dict[FLASK_CONFIGURATION])
app.secret_key = secret_key
Bootstrap(app)
assets = Environment(app)
js_files = Bundle('justgage.js', 'raphael-2.1.4.min.js', filters='rjsmin', output='gen/minified.js')
assets.register('js_files', js_files)
nav.init_app(app)
from .blueprints import bp
app.register_blueprint(bp)
global celery
celery = make_celery(app)
@app.errorhandler(404)
def fournotfour(_):
return render_template("404page.html"), 404
@app.errorhandler(500)
def fivezerozero(_):
return render_template("500page.html"), 500
return app
python类Bundle()的实例源码
def assets(self, app):
bundles = {
'home_js': Bundle(
'bootstrap/js/jquery.min.js',
'bootstrap/bootstrap/js/bootstrap.min.js',
output='assets/home.js',
filters='jsmin'),
'home_css': Bundle(
'bootstrap/bootstrap/css/bootstrap.min.css',
'bootstrap/css/honmaple.css',
output='assets/home.css',
filters='cssmin')
}
if self.use_auth:
auth_js = ('bootstrap/js/honmaple.js', 'bootstrap/js/login.js')
bundles['home_js'].contents = bundles['home_js'].contents + auth_js
if self.css:
bundles['home_css'].contents = bundles[
'home_css'].contents + self.css
if self.js:
bundles['home_js'].contents = bundles['home_js'].contents + self.js
assets = Environment(app)
assets.register(bundles)
def init(app=None):
app = app or Flask(__name__)
with app.app_context():
env = Environment(app)
env.load_path = [path.join(path.dirname(__file__), 'assets')]
env.url = app.static_url_path
env.directory = app.static_folder
env.auto_build = app.debug
env.manifest = 'file'
scss = Bundle('stylesheet.scss', filters='pyscss', output='stylesheet.css')
env.register('scss_all', scss)
bundles = [scss]
return bundles
def css_default():
"""Default CSS for the entire app"""
BOOTSTRAP_LESS = "less/bootstrap.less"
return Bundle(
BOOTSTRAP_LESS,
filters="less",
depends="less/**/*.less",
output="compiled/%(version)s.css", )
def css_blog():
"""Default CSS for the entire app"""
BOOTSTRAP_LESS = "less/bootstrap.less"
return Bundle(
BOOTSTRAP_LESS,
filters="less",
depends="less/**/*.less",
output="compiled/bootstrap.css", )
def create_assets(assets):
# js = Bundle(
# 'vendor/jquery/dist/jquery.min.js',
# output='js/libs.js'
# )
# assets.register('JS_FRAMEWORS', js)
css = Bundle(
'css/sticky-footer.css',
output='css/min.css'
)
assets.register('CSS_FRAMEWORKS', css)
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
bootstrap.init_app(app)
mail.init_app(app)
moment.init_app(app)
db.init_app(app)
login_manager.init_app(app)
pagedown.init_app(app)
assets.init_app(app)
if config_name == "testing":
assets._named_bundles = {} # quick fix for flask testng and flask assets
js = Bundle('js/index.js',filters='jsmin', output='gen/packed.js')
assets.register('js_all', js)
css = Bundle('css/index.css',filters='cssmin',output='css/min.css')
assets.register('css_all', css)
from main import main as main_blueprint
app.register_blueprint(main_blueprint)
from auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth')
from admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')
from api_1_0 import api as api_1_0_blueprint
app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0')
return app