Esempio n. 1
0
def create_app(config):
    """
    创建app
    """
    app = Flask(__name__)
    api = Api(app, prefix='/api/v1')
    # 保留flask原生异常处理
    handle_exception = app.handle_exception
    handle_user_exception = app.handle_user_exception
    # 添加配置
    app.config.from_object(config)
    # 解决跨域
    app.after_request(_access_control)
    # 自定义abort 400 响应数据格式
    flask_restful.abort = _custom_abort
    # 认证
    # from apps.auth.auths import Auth
    # auth = Auth()
    # jwt = JWT(app, auth.authenticate, auth.identity)

    # 数据库初始化
    db.init_app(app)
    db.create_all(app=app)
    login_manager.session_protection = "strong"
    login_manager.init_app(app)

    # 注册蓝图
    register_blueprint(app)
    # from apps.routes import api_v1
    # from apps.articles import articles
    # from apps.users import users
    # app.register_blueprint(api_v1, url_prefix='/api/v1')
    # app.register_blueprint(articles, url_prefix='/articles')
    # app.register_blueprint(users, url_prefix='/users')
    # # 使用flask原生异常处理程序
    app.handle_exception = handle_exception
    app.handle_user_exception = handle_user_exception
    return app
Esempio n. 2
0
from apps import app

if __name__ == '__main__':
    with app.app_context():
        from apps.models import db
        db.create_all()
    app.run()
Esempio n. 3
0
def initdb():
    '''Creates all database tables.'''
    db.create_all()
Esempio n. 4
0
 def before_request():
     g.me = None
     db.create_all()
Esempio n. 5
0
def register_plugin(app):
    from apps.models import db
    db.init_app(app)
    with app.app_context():
        db.create_all()
Esempio n. 6
0
def create_db():
    """Create database for """
    db.create_all()
Esempio n. 7
0
 def before_request():
     db.create_all()