Ejemplo n.º 1
0
def build(build_destination=None):
    """Create a static version of the site with Frozen-Flask"""
    from flaskext.frozen import Freezer
    if build_destination is not None:
        app.config['FREEZER_DESTINATION'] = build_destination
    else:
        app.config['FREEZER_DESTINATION'] = os.path.join(app.config["SOURCE"],
                                                         "_build")
    freezer = Freezer(app)
    freezer.freeze()
Ejemplo n.º 2
0
def build(build_destination=None):
    """Create a static version of the site with Frozen-Flask"""
    try:
        from flaskext.frozen import Freezer
    except ImportError:
        import sys
        sys.exit("To create a static version of the site you need the "
                 "Frozen-Flask package")

    if build_destination is not None:
        current_app.config['FREEZER_DESTINATION'] = build_destination
    else:
        current_app.config['FREEZER_DESTINATION'] = os.path.join(
        current_app.config["SOURCE"], "_build")

    freezer = Freezer(current_app)
    freezer.freeze()
Ejemplo n.º 3
0
def init_app(defer_init_app=False):
    app = Flask(__name__)
    app.register_module(admin_module, url_prefix='/admin')
    if defer_init_app:
        freezer = Freezer()
    else:
        freezer = Freezer(app)

    @app.route('/')
    def index():
        return 'Main index'

    @app.route('/page/<name>/')
    def page(name):
        return u'Hello\xa0World! ' + name

    @app.route('/where_am_i/')
    def where_am_i():
        return (url_for('where_am_i') + ' ' +
                url_for('where_am_i', _external=True))

    @app.route('/robots.txt')
    def robots_txt():
        content = 'User-agent: *\nDisallow: /'
        return app.response_class(content, mimetype='text/plain')

    @app.route('/product_<int:product_id>/')
    def product(product_id):
        return 'Product num %i' % product_id

    @freezer.register_generator
    def product():
        # endpoint, values
        yield 'product', {'product_id': 0}
        # Just a `values` dict. The endpoint defaults to the name of the
        # generator function, just like with Flask views
        yield {'product_id': 1}
        # single string: url
        yield '/product_2/'
        
        yield 'page', {'name': u'I løvë Unicode'}
    
    if defer_init_app:
        freezer.init_app(app)

    return app, freezer