Python flask_assets 模块,Environment() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用flask_assets.Environment()

项目:tweet-analysis    作者:D4D3VD4V3    | 项目源码 | 文件源码
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
项目:flask-maple    作者:honmaple    | 项目源码 | 文件源码
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)
项目:mnogoznal    作者:nlpub    | 项目源码 | 文件源码
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
项目:web_develop    作者:dongweiming    | 项目源码 | 文件源码
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
项目:maps4all-signup    作者:hack4impact    | 项目源码 | 文件源码
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')

    return app
项目:Konsole    作者:ColinHaley    | 项目源码 | 文件源码
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

#    app.config['SERVER_NAME']='0.0.0.0:80'
#    app.config



    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')

    return app
项目:Flask-MVC-Template    作者:CharlyJazz    | 项目源码 | 文件源码
def create_app(config_name):
    global user_datastore
    app = Flask(__name__)

    app.config.from_object(app_config[config_name])

    csrf = CSRFProtect()
    csrf.init_app(app)

    assets = Environment(app)
    create_assets(assets)

    via = Via()
    via.init_app(app)

    # Code for desmostration the flask upload in several models - - - -

    from user import user_photo
    from restaurant import restaurant_photo
    from food import food_photo

    configure_uploads(app, (restaurant_photo, food_photo, user_photo))

    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    if not database_exists(engine.url):
        create_database(engine.url)

    security = Security(app, user_datastore, register_form=SecurityRegisterForm)

    create_security_admin(app=app, path=os.path.join(os.path.dirname(__file__)))

    with app.app_context():
        db.init_app(app)
        db.create_all()
        user_datastore.find_or_create_role(name='admin', description='Administrator')
        db.session.commit()
        user_datastore.find_or_create_role(name='end-user', description='End user')
        db.session.commit()

    @app.route('/', methods=['GET'])
    @app.route('/home', methods=['GET'])
    def index():
        return render_template('index.html')

    @app.errorhandler(403)
    def forbidden(error):
        return render_template('error/403.html', title='Forbidden'), 403

    @app.errorhandler(404)
    def page_not_found(error):
        return render_template('error/404.html', title='Page Not Found'), 404

    @app.errorhandler(500)
    def internal_server_error(error):
        db.session.rollback()
        return render_template('error/500.html', title='Server Error'), 500

    return app