示例#1
0
def create_app(config=None):
    """
    Create and initialise the application.
    """
    app = Flask(__name__)
    app.config.from_pyfile('%s/config/default.py' % app.root_path)

    if config:
        app.config.from_pyfile(config)
    elif os.getenv('FLASK_CONFIG'):
        app.config.from_envvar('FLASK_CONFIG')

    logger.init(app)
    jinja.init(app)
    assets.init(app)

    app.register_blueprint(views.blueprint)

    @app.errorhandler(404)
    def not_found(error):
        return render_template('errors/404.html'), 404

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

    @app.errorhandler(500)
    def server_error(error):
        return render_template('errors/default.html'), 500

    return app
示例#2
0
def create_app(config=None):
    """
    Create and initialise the application.
    """
    app = Flask(__name__)
    app.config.from_pyfile('%s/config/default.py' % app.root_path)

    if config:
        app.config.from_pyfile(config)
    elif os.getenv('FLASK_CONFIG'):
        app.config.from_envvar('FLASK_CONFIG')

    logger.init(app)
    jinja.init(app)
    assets.init(app)

    app.register_blueprint(views.blueprint)

    @app.errorhandler(404)
    def not_found(error):
        return render_template('errors/404.html'), 404

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

    @app.errorhandler(500)
    def server_error(error):
        return render_template('errors/default.html'), 500

    return app
示例#3
0
文件: __init__.py 项目: dansimau/coke
def create_app(config=None):
    """
    Create and initialise the application.
    """
    app = Flask(__name__)
    app.config.from_pyfile('%s/config/default.py' % app.root_path)

    if config:
        app.config.from_pyfile(config)
    elif os.getenv('FLASK_CONFIG'):
        app.config.from_envvar('FLASK_CONFIG')

    db.init(app)
    jinja.init(app)

    app.register_blueprint(views.main)

    return app
示例#4
0
def create_app(config=None):
    """
    Create and initialise the application.
    """
    app = Flask(__name__)
    app.config.from_pyfile('%s/config/default.py' % app.root_path)

    if config:
        app.config.from_pyfile(config)
    elif os.getenv('FLASK_CONFIG'):
        app.config.from_envvar('FLASK_CONFIG')

    logger.init(app)
    jinja.init(app)
    uploads.init(app)
    assets.init(app)

    # Add request hook to change x-sendfile to x-accel-redirect (for nginx)
    @request_finished.connect_via(app)
    def nginx_sendfile_patch(sender, response):
        if 'X-Sendfile' in response.headers:
            filepath = '/' + relpath(
                response.headers['X-Sendfile'],
                abspath(app.config['UPLOADS_DEFAULT_DEST']))
            response.headers['X-Accel-Redirect'] = filepath
            del response.headers['X-Sendfile']

    app.register_blueprint(views.blueprint)
    app.register_blueprint(api.blueprint)

    @app.errorhandler(404)
    def not_found(error):
        return render_template('errors/404.html'), 404

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

    @app.errorhandler(500)
    def server_error(error):
        return render_template('errors/default.html'), 500

    return app
示例#5
0
def create_app(config=None):
    """
    Create and initialise the application.
    """
    app = Flask(__name__)
    app.config.from_pyfile('%s/config/default.py' % app.root_path)

    if config:
        app.config.from_pyfile(config)
    elif os.getenv('FLASK_CONFIG'):
        app.config.from_envvar('FLASK_CONFIG')

    logger.init(app)
    jinja.init(app)
    uploads.init(app)
    assets.init(app)

    # Add request hook to change x-sendfile to x-accel-redirect (for nginx)
    @request_finished.connect_via(app)
    def nginx_sendfile_patch(sender, response):
        if 'X-Sendfile' in response.headers:
            filepath = '/' + relpath(response.headers['X-Sendfile'],
                                     abspath(app.config['UPLOADS_DEFAULT_DEST']))
            response.headers['X-Accel-Redirect'] = filepath
            del response.headers['X-Sendfile']

    app.register_blueprint(views.blueprint)
    app.register_blueprint(api.blueprint)

    @app.errorhandler(404)
    def not_found(error):
        return render_template('errors/404.html'), 404

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

    @app.errorhandler(500)
    def server_error(error):
        return render_template('errors/default.html'), 500

    return app
示例#6
0
文件: jmcgi.py 项目: cobysy/jmdictdb
def jinja_page(tmpl, output=sys.stdout, **kwds):
    httphdrs = kwds.get('HTTP', None)
    if not httphdrs:
        if not kwds.get('NoHTTP', None):
            httphdrs = "Content-type: text/html\n"
    if not httphdrs: html = ''
    else: html = httphdrs + "\n"
    env = jinja.init()
    html += jinja.render(tmpl, kwds, env)
    if output: print(html, file=output)
    return html
示例#7
0
文件: run.py 项目: hansihe/FauxForum
                 assets_folder + 'js/modernizr.js',
                 assets_folder + 'js/foundation/foundation.js',
                 assets_folder + 'js/foundation/foundation.topbar.js',
                 assets_folder + 'js/foundation/foundation.dropdown.js',
                 assets_folder + 'js/foundation/foundation.alert.js',
                 assets_folder + 'js/foundation/foundation.tooltip.js',
                 filters=None if app.debug else 'rjsmin', output='gen/js/main.%(version)s.js')
environment.register('js_main', js_main)

import ext
ext.init(app)
import models
ext.db.create_all()

import jinja
jinja.init(app)

from blueprints import auth, forum, static
app.register_blueprint(auth.blueprint)
app.register_blueprint(forum.blueprint)
app.register_blueprint(static.blueprint)

from models.thread import Thread
from models.post import Post
from sqlalchemy.orm import aliased

@app.route('/')
def index():
    #last_post = Post.query.order_by(Post.id.desc()).limit(1).subquery()
    #last_post_alias = aliased(Post, last_post)
    #threads = ext.db.session.query(Thread, last_post_alias).join(last_post_alias, Thread.id == last_post_alias.thread_id).order_by(Thread.id.desc()).all()