示例#1
0
def register_extension(app):
    '''
    加载扩展模块,并且配置各个模块
    :param app:
    :return:
    '''
    # 加载扩展模块
    from extension import jwt
    from extension import db
    from extension import ma
    from extension import migrate
    #  将扩展模块注册到app 中
    db.init_app(app)
    jwt.init_app(app)
    ma.init_app(app)
    migrate.init_app(app, db=db)

    # 配置jwt
    config_jwt(jwt=jwt)

    return None
示例#2
0
def create_app(config_name):
    app = Flask(__name__)
    # config website
    app.config.from_object(config_name)
    app.response_class = JSONResponse

    db.init_app(app)
    bcrypt.init_app(app)

    @app.errorhandler(404)
    def page_not_found(err):
        return render_template('404.html'), 404

    # register blueprint, add url
    app.register_blueprint(common, url_prefix='/shangshanfan')
    app.register_blueprint(article, url_prefix='/shangshanfan/article')
    app.register_blueprint(picture, url_prefix='/shangshanfan/picture')
    app.register_blueprint(album, url_prefix='/shangshanfan/album')
    app.register_blueprint(author, url_prefix='/shangshanfan/author')
    app.register_blueprint(geek, url_prefix='/shangshanfan/geek')

    return app
示例#3
0
def initialize_app(app, profile=False, config="webApp.config.AppConfig"):
    app.config.from_object(config)
    db.init_app(app)
    db.drop_all(app=app)
    db.create_all(app=app)
    redis_client.init_app(app=app)
    mongo_client.init_app(app=app)
    login_manager.init_app(app=app)
    csrf.init_app(app=app)
    cors.init_app(app=app)
    celery.init_app(app=app)
    if profile:
        from werkzeug.contrib.profiler import ProfilerMiddleware
        """
        请求性能测试参数说明:
            tottime : 在这个函数中所花费所有时间。
            percall : 是 tottime 除以 ncalls 的结果。
            cumtime : 花费在这个函数以及任何它调用的函数的时间。
            percall : cumtime 除以 ncalls。
            filename:lineno(function) : 函数名以及位置。
        """
        app.config['PROFILE'] = True
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])

    app.register_blueprint(rest_api_view)

    csrf.exempt(rest_api_view)  # escape csrf protect

    if AppConfig.APP_SLOW_LOG:
        slow_logger_handler = generate_logger_handler(
            "app-slow",
            is_stream_handler=False,
            add_error_log=False,
            formatter=Formatter("%(asctime)s %(message)s"))
        app.slow_logger = create_logger("app-slow",
                                        handlers=slow_logger_handler)
    app.logger_name = "app"
    app.logger.setLevel(10)
    app.logger.handlers = generate_logger_handler("app")  # handlers is a list
示例#4
0
def extensions(app):
    db.init_app(app)
    flask_login.init_app(app)

    return None
示例#5
0
# -*- coding: utf-8 -*-

from flask import Flask

from extension import db
from web import web

SECRET_KEY = 'TeamBuilding'
DEBUG = True

SQLALCHEMY_DATABASE_URI = 'mysql://root:@localhost/TBuilding'

app = Flask(__name__)
app.config.from_object(__name__)

db.init_app(app)

app.register_blueprint(web, url_prefix='/web')

with app.app_context():
    db.create_all()
    #print "ok"

if __name__ == '__main__':
    app.run()
示例#6
0
from flask import Flask
from extension import admin, db
import config
# from flask_admin import AdminIndexView
from flask_admin.contrib.sqlamodel import ModelView
from models import User

app = Flask(__name__)

app.config['SECRET_KEY'] = '123456790'

app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'  # 부트스트랩 테마

db.init_app(app)  # flask와 sqlalchemy 연동
admin.init_app(app)  # flask와 admin 연동


class ModelView2(ModelView):
    can_create = True
    can_edit = True
    can_delete = True
    can_view_details = False
    can_export = False
    create_modal = True


admin.add_view(ModelView2(User, db.session))  # model view

app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_FILE
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
def configure_extensions(app):
    db.init_app(app)
    jwt.init_app(app)
示例#8
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(DevelopConfig)
    db.init_app(app)
    app.register_blueprint(article_api, url_prefix='/blog/')
    return app
示例#9
0
# -*- coding: utf-8 -*-

from flask import Flask

from extension import db
from web import web

SECRET_KEY = 'TeamBuilding'
DEBUG=True

SQLALCHEMY_DATABASE_URI = 'mysql://root:@localhost/TBuilding'

app = Flask(__name__)
app.config.from_object(__name__)

db.init_app(app)

app.register_blueprint(web, url_prefix='/web')

with app.app_context():
    db.create_all()
    #print "ok"

if __name__ == '__main__':
    app.run()