Example #1
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    db.init_app(app)
    register_blueprints(app)

    return app
Example #2
0
def create_app(config):
    app = Flask(__name__)
    # app.config.from_object(configs.get(config))
    app.config.from_object(DevelopmentConfig)
    db.init_app(app)
    Migrate(app, db)
    register_all_blueprint(app)
    return app
Example #3
0
def create_app(config):
    """app factory"""
    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    db.init_app(app)
    Migrate(app, db)
    register_blueprints(app)
    return app
Example #4
0
def create_app(config):

    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    #初始化SQLAlchemy
    db.init_app(app)
    register_blueprints(app)
    Migrate(app,db)
    return app
Example #5
0
def create_app(config):
    #创建工厂函数,传入变量类型参数
    app=Flask(__name__)
    app.config.from_object(configs.get(config))
    #init_app是sqlalchemy的传入参数,直接创建为sqlalchemy(app),分开了就必须要使用init_app参数
    db.init_app(app)
    #创建蓝图
    register_blueprints(app)
    return app
Example #6
0
def create_app(config):
    ''' 根据传人的 config 加载不同的配置 '''

    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    # SQLAlchemy 的初始化方式改为使用 init_app
    db.init_app(app)
    register_blueprints(app)

    return app
Example #7
0
def create_app(config):
    """ load different configuration based on argument config
    """
    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    # initialize SQLAlchemy object in models.py
    db.init_app(app)
    register_blueprints(app)

    return app
Example #8
0
def register_extensions(app):
    db.init_app(app)
    Migrate(app, db)
    login_manager = LoginManager()
    login_manager.init_app(app)

    @login_manager.user_loader
    def user_loader(id):
        return User.query.get(id)

    login_manager.login_view = 'front.login'
Example #9
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    db.init_app(app)
    register_blueprints(app)

    @app.errorhandler(404)
    def not_found(e):
        return 'Not Found'

    return app
Example #10
0
def create_app(config):
    """此函数为工厂函数,用于创建应用对象并返回
    """

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

    db.init_app(app)
    register_blueprints(app)

    return app
Example #11
0
def create_app(config):
    '''可以根据传入的config名称,加载不同的配置'''
    app = Flask(__name__)
    app.config.from_object(configs.get(config))

    #SQLAlchemy的初始方式改为使用init_app
    #连接数据库与flask
    db.init_app(app)

    register_blueprints(app)

    return app
def register_extensions(app):
    db.init_app(app)
    Migrate(app, db)

    login_manager = LoginManager()
    login_manager.init_app(app)  # 将 LoginManager 注册到 app 和 数据库,即初始化 app

    @login_manager.user_loader  # 用 user_loader 装饰器注册一个函数,以加载用户对象
    def user_loader(id):
        return user.query.get(id)

    login_manager.login_view = 'front.login'  # login_view 设置的是登录页面的路由,有了它,当用 flask-login 提供的 login_required 装时期保护一个路由,如果用户未登录,那么就被重定向 login_view 页面
Example #13
0
def register_extensions(app):
    db.init_app(app)
    Migrate(app, db)

    login_manager = LoginManager()
    login_manager.init_app(app)

    @login_manager.user_loader  #告知flask-login如何加载用户对象
    def user_loader(id):
        return User.query.get(id)

    # 设置登录页面的路由,如果用户未登录,就会被重定向到login_view指定的页面
    login_manager.login_view = 'front.login'
Example #14
0
def register_extensions(app):
    db.init_app(app)
    Migrate(app, db)
    # 从Flask_login导入LoginManager(登录管理器)后,创建该类的实例对象
    login_manager = LoginManager()
    login_manager.init_app(app)
    # 使用user_loader装饰器注册一个函数,用来告诉flask_login如何加载用户对象
    @login_manager.user_loader
    def user_loader(id):
        return User.query.get(id)

    login_manager.login_view = 'front.login'
    login_manager.login_message = '登陆后才能访问该网页'
    login_manager.login_message_category = 'danger'
Example #15
0
def register_extensions(app):
    db.init_app(app)
    Migrate(app, db)
    login_manager = LoginManager()
    login_manager.init_app(app)
    sockets = Sockets(app)
    sockets.register_blueprint(ws)

    @login_manager.user_loader
    def user_loader(id):
        return User.query.get(id)

    login_manager.login_view = 'front.login'
    login_manager.login_message = '请先登录'
    login_manager.login_message_category = 'danger'
Example #16
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(configs.get(config))
    db.init_app(app)
    register_blueprint(app)
    return app
    @app.route('/')
    def index():
        courses = Course.query.all()
        return render_template('index.html', courses=courses)

    @app.route('/admin')
    def admin_index():
        return 'admin'

    return app
Example #17
0
def create_app(config):

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

    db.init_app(app)

    @app.route('/')
    def index():
        companys=Company.query.all()
        return render_template('index.html',companys=companys)
    @app.route('/admin')
    def admin_index():
        return 'admin'

    return app
Example #18
0
def register_extensions(app):
	#SQLAlchemy的初始方式改为使用init_app
	#连接数据库与flask
	db.init_app(app)
	
	#将db注册到app上
	Migrate(app,db)
	
	login_manager = LoginManager()
	login_manager.init_app(app)
	
	@login_manager.user_loader
	def user_loader(id):
		return User.query.get(id)
		
	login_manager.login_view = 'front.login'
Example #19
0
def register_extensions(app):
    """注册扩展
    """

    db.init_app(app)
    Migrate(app, db)

    login_manager = LoginManager()
    login_manager.init_app(app)

    @login_manager.user_loader
    def user_loader(id):
        return User.query.get(id)

    login_manager.login_view = 'front.login'
    login_manager.login_message = '需要先登录,然后才能访问此页面。'
    login_manager.login_message_category = 'warning'
Example #20
0
    login_manager.login_view = 'front.login'

def register_blueprints(app):
    from .handlers import front, course, admin
    app.register_blueprint(front)
    app.register_blueprint(course)
    app.register_blueprint(admin)
=======

def register_blueprints(app):
    from .handlers import front, course, admin, user
    app.register_blueprint(front)
    app.register_blueprint(course)
    app.register_blueprint(admin)
    app.register_blueprint(user)
>>>>>>> 94eabd4a7886dac73ee0b413078e4000d94daeab

def create_app(config):
    app = Flask(__name__)
    app.config.from_object(configs.get(config))
<<<<<<< HEAD
    register_extensions(app)
=======
    db.init_app(app)
>>>>>>> 94eabd4a7886dac73ee0b413078e4000d94daeab
    register_blueprints(app)

    return app