示例#1
0
def create_app():
    """
    主入口文件创建app,供其他蓝图使用
    :return: 返回一个app
    """
    app = Flask(__name__)
    # 防止csrf注入攻击
    CSRFProtect(app)
    # 注册蓝图模块
    app.register_blueprint(cms_bp, url_prefix="/cms")
    app.register_blueprint(common_bp, url_prefix="/common")
    app.register_blueprint(front_bp)

    # 导入配置文件
    app.config.from_object(config)
    # 数据库db绑定到app上
    db.init_app(app)
    # 邮件mail绑定到app上
    mail.init_app(app)
    # Redis数据库cache绑定到app上
    cache.init_app(app)
    # 后台登录login_manager初始化app
    # cms_login_manager.init_app(app)
    # 前台登录login_manager绑定到app上
    front_login_manager.init_app(app)
    # login_manager.blueprint_login_views = "cms.login"
    # login_manager.blueprint_login_views = "/signin"
    front_login_manager.blueprint_login_views = {
        'cms': "cms.login",
        'front': 'front.signin'
    }

    # 富文本编辑器绑定到app上
    ckeditor.init_app(app)
    return app
示例#2
0
def create_app():
    app = Flask(__name__, static_folder='../static')
    app.config.from_object(DevelopmentConfig)
    db.init_app(app=app)
    cors.init_app(app=app, support_credentials=True)  # 支持证书
    cache.init_app(app=app, config=config)
    init_api(app=app)
    return app
示例#3
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(settings.Development)

    db.init_app(app=app)
    cache.init_app(app=app, config=config)
    cors.init_app(app=app, supports_credentials=True)
    app.register_blueprint(user_bp)
    app.register_blueprint(news_bp)
    print(app.url_map)
    return app
示例#4
0
def create_app():
    app = Flask(__name__, static_folder='../static')
    app.config.from_object(DevelopmentConfig)

    db.init_app(app=app)
    cors.init_app(app=app, supports_credentials=True)
    cache.init_app(app=app, config=config)
    # 注册蓝图
    app.register_blueprint(news_bp)
    app.register_blueprint(user_bp)
    print(app.url_map)
    return app
示例#5
0
def create_app(configName):
    app = Flask(__name__)
    app.config.from_object(configName)

    app.register_blueprint(bp_user)
    app.register_blueprint(bp_news)

    db.init_app(app)
    cache.init_app(app)
    cors.init_app(app=app, supports_credentials=True)

    print(app.url_map)
    return app
示例#6
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(DevelopmentConfig)
    # 给db对象初始化app
    db.init_app(app)
    csrf.init_app(app)
    cache.init_app(app, config=config)
    # 注册蓝图
    app.register_blueprint(blog_bp)
    app.register_blueprint(article_bp)

    return app
示例#7
0
def create_app():

    app = Flask(__name__)
    with app.app_context():
        app.config.from_object(DevConfig)

        # 初始化flask_session
        session.init_app(app)
        # 初始化cache
        cache.init_app(app)

        # 注册蓝图
        register_blueprint(app)

        # 初始化日志-按天分隔
        handler = TimedRotatingFileHandler(Config.LOG_PATH + '/flask.log',
                                           when="D",
                                           interval=1,
                                           backupCount=15,
                                           encoding="UTF-8",
                                           delay=False,
                                           utc=True)
        formatter = logging.Formatter(
            "[%(asctime)s][%(filename)s:%(lineno)d]"
            "[%(levelname)s][%(thread)d] - %(message)s")
        # 为日志记录器设置记录格式
        handler.setFormatter(formatter)
        # 为全局的日志工具对象(flaks app使用的)加载日志记录器
        # logging.getLogger().addHandler(handler)
        app.logger.addHandler(handler)

        # 初始化db
        db.app = app
        db.init_app(app)
        db.engine.pool._use_threadlocal = True
        db.Model.to_dict = db_to_dict()

        # 初始化数据库
        init_db(app)

        # 初始化flask-login
        login_manager.init_app(app)  # 初始化应用
        login_manager.login_view = 'login'  # 设置用户登录视图函数 endpoint
        if app.config["IS_MOCK_LOGIN"]:
            login_manager.anonymous_user = MyAnonymousUser

    return app
示例#8
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(DevelopmentConfig)
    # 初始化db
    db.init_app(app=app)
    # 初始化bootstrap
    bootstrap.init_app(app)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(article_bp)
    app.register_blueprint(goods_bp)
    # print(app.url_map)
    # 初始化缓存文件
    cache.init_app(app, config)
    return app
示例#9
0
文件: __init__.py 项目: sky-boy777/bs
def create_app():
    # 创建app,并且指定templates、static文件夹位置
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings)  # 加载配置文件

    db.init_app(app)  # 初始化数据库
    csrf.init_app(app)  # 初始化全局csrf
    mail.init_app(app)  # 初始化发送邮件类
    cache.init_app(app)  # 初始化缓存

    # 注册蓝图
    app.register_blueprint(main_bp)  # 前台展示蓝图
    app.register_blueprint(user_bp)  # 用户模块蓝图
    app.register_blueprint(admin_bp)  # 后台管理蓝图

    return app
示例#10
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings)
    db.init_app(app)  # 初始化db

    # 初始化csrf,需要配置SECRET_KEY
    # csrf.init_app(app=app)

    # 初始化restful api
    api.init_app(app=app)

    # 初始化cors解决跨域
    cors.init_app(app=app, supports_credentials=True)  # 后面是支持证书认证

    # 初始化缓存文件
    cache.init_app(
        app=app,
        config={
            'CACHE_TYPE': 'redis',  # 缓存类型
            # 'CACHE_REDIS_HOST': 'localhost',  # 地址,默认使用0号数据库
            # 'CACHE_REDIS_PORT': 6379  # 端口号
            'CACHE_REDIS_URL':
            'redis://@localhost:6379/2'  # 无密码, 有密码:redis://user:password@localhost:6379/2
        })

    # 初始化bootstrap两种方法
    bootstrap.init_app(app)
    # Bootstrap(app)

    # 注册蓝图(模块:user_app,blog_app...)
    app.register_blueprint(app_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(restful_bp)
    app.register_blueprint(api_user_bp)

    return app
示例#11
0
def register_extensions(app):
    FlaskDB(app, db)
    mail.init_app(app)
    cache.init_app(app)
    administrator_page, show_post_list, image
from exts import db, cache, mail, login_manager

app = Flask(__name__)
app.config.from_object(config)
app.register_blueprint(register_login.register_login)
app.register_blueprint(search.search)
app.register_blueprint(club_queries.club_queries)
app.register_blueprint(view_post.view_post)
app.register_blueprint(club_homepage.club_homepage)
app.register_blueprint(administrator_page.administrator_page)
app.register_blueprint(manage_post.manage_post)
app.register_blueprint(club_admin_manage.club_admin_manage)
app.register_blueprint(show_post_list.show_post_list)
app.register_blueprint(image.image)

db.init_app(app)
cache.init_app(app)
mail.init_app(app)
login_manager.init_app(app)
login_manager.session_protection = 'strong'


@app.route('/')
def hello():
    return '<h1>Hello World!</h1>'


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=False)