Using flask assets.

This commit is contained in:
Alexis Lahouze 2015-08-16 00:33:35 +02:00
parent 642b8c5b98
commit fe53de1633
2 changed files with 20 additions and 3 deletions

View File

@ -18,9 +18,10 @@ from contextlib import contextmanager
import logging
from flask import Flask
from flask import Flask, redirect, url_for
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.bower import Bower
from flask.ext.assets import Environment, Bundle
from . import config
@ -71,7 +72,7 @@ def session_aware(f):
# Must be after db declaration because the blueprints may need it.
from .api import api
from .frontend import frontend
from .frontend import frontend, frontend_js, frontend_css
app.register_blueprint(frontend, url_prefix='/app')
app.register_blueprint(api, url_prefix='/api')
@ -80,5 +81,14 @@ app.register_blueprint(api, url_prefix='/api')
app.config['BOWER_COMPONENTS_ROOT'] = "../bower_components"
app.config['BOWER_TRY_MINIFIED'] = not config.debug
bower = Bower(app)
assets = Environment(app)
assets.register('frontend_js', frontend_js)
assets.register('frontend_css', frontend_css)
@app.route('/')
def index():
return redirect(url_for('frontend.index'))

View File

@ -1,4 +1,5 @@
from flask import Blueprint, render_template
from flask.ext.assets import Environment, Bundle
frontend = Blueprint(
'frontend',
@ -8,6 +9,12 @@ frontend = Blueprint(
)
frontend_js = Bundle('frontend/js/app.js', 'frontend/js/accounts.js',
'frontend/js/entries.js', 'frontend/js/scheduler.js')
frontend_css = Bundle('frontend/css/main.css')
@frontend.route('/', defaults={'path': 'accounts'})
@frontend.route('/<path:path>')
def index(path):