Exemple #1
0
def register_extensions(app):
    bootstrap.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    csrf.init_app(app)
    ckeditor.init_app(app)
    moment.init_app(app)
    toolbar.init_app(app)
    migrate.init_app(app, db)
Exemple #2
0
def create_app(config_class=Config):
    app = Flask(__name__)
    # app.config['SECRET_KEY']='dai3hoahudhiuahduiah'
    # app.config['BABEL_DEFAULT_LOCALE'] = 'zh_Hans_CN'
    app.config.from_object(config_class)

    mongo.init_app(app)
    login.init_app(app)
    mail.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    babel.init_app(app)
    from app.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    from app.auth import bp as auth_bp
    app.register_blueprint(auth_bp, url_prefix='/auth')

    from app.main import bp as main_bp
    app.register_blueprint(main_bp)

    from app.admin import bp as admin_bp
    app.register_blueprint(admin_bp, url_prefix='/admin')

    if not app.debug and not app.testing:
        if app.config['MAIL_SERVER']:
            auth = None
            if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
                auth = (app.config['MAIL_USERNAME'],
                        app.config['MAIL_PASSWORD'])
            secure = None
            if app.config['MAIL_USE_TLS']:
                secure = ()
            mail_handler = SMTPHandler(
                mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
                fromaddr='no-reply@' + app.config['MAIL_SERVER'],
                toaddrs=app.config['ADMINS'],
                subject='Microblog Failure',
                credentials=auth,
                secure=secure)
            mail_handler.setLevel(logging.ERROR)
            app.logger.addHandler(mail_handler)
        if not os.path.exists('logs'):
            os.mkdir('logs')
        file_handler = RotatingFileHandler('logs/microblog.log',
                                           maxBytes=10240,
                                           backupCount=10)
        file_handler.setFormatter(
            logging.Formatter(
                '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
            ))
        file_handler.setLevel(logging.INFO)
        app.logger.addHandler(file_handler)

        app.logger.setLevel(logging.INFO)
        app.logger.info('Project System Startup')
    return app
def create_app(config_class=Config):
    app = Flask(__name__)
    # app.config['SECRET_KEY']='dai3hoahudhiuahduiah'
    # app.config['BABEL_DEFAULT_LOCALE'] = 'zh_Hans_CN'
    app.config.from_object(config_class)

    bootstrap.init_app(app)
    babel.init_app(app)

    from app.main import bp as main_bp
    app.register_blueprint(main_bp)

    return app
Exemple #4
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    #环境的设置
    app.config.from_object(settings.DevelopmentConfig)
    #初始化db
    db.init_app(app)
    #初始化缓存文件
    cache.init_app(app=app, config=config)
    #初始化bootstrap
    bootstrap.init_app(app)
    app.register_blueprint(user_bp)
    app.register_blueprint(article_bp)
    return app
Exemple #5
0
def creat_app():
    # app是一个核心对象,重新定义template和static文件夹位置
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(DevelopmentConfig)  # 增加配置

    # 初始化db,将db对象与app进行关联
    db.init_app(app)

    # 初始化bootstrap
    bootstrap.init_app(app=app)

    # 注册蓝图
    app.register_blueprint(user_bp)  # 将蓝图对象绑定到app上
    # print(app.url_map)

    return app
Exemple #6
0
def create_app(config_class=Config):
    app = Flask(__name__)
    # app.config['SECRET_KEY']='dai3hoahudhiuahduiah'
    # app.config['BABEL_DEFAULT_LOCALE'] = 'zh_Hans_CN'
    app.config.from_object(config_class)

    db.init_app(app)  # SQLite初始化
    migrate.init_app(app, db)  # 数据库迁移初始化
    bootstrap.init_app(app)  # Bootstrap初始化
    babel.init_app(app)  # I18nL10n 初始化
    images.init_app(app)  # Imagine Normalise 初始化
    login.init_app(app)  # 用户系统 初始化
    login.login_view = 'admin.login'
    mail.init_app(app)  # 邮件系统 初始化

    configure_uploads(app, (photos, sphotos, videos))  # 文件系统初始化
    patch_request_class(app)  # 文件大小限制,默认为16MB

    cache.init_app(app, config={'CACHE_TYPE': 'simple'})  # 页面缓存 初始化

    from app.main import bp as main_bp  # 首页注册
    app.register_blueprint(main_bp)

    from app.module import bp as module_bp  # 课程模块注册
    app.register_blueprint(module_bp)

    from app.experiment import bp as experiment_bp  # 通识实验注册
    app.register_blueprint(experiment_bp, url_prefix='/experiment')

    from app.guide import bp as guide_bp  # 课程指南注册
    app.register_blueprint(guide_bp, url_prefix='/guide')

    from app.admin import bp as admin_bp  # 管理页面注册
    app.register_blueprint(admin_bp, url_prefix='/admin')

    from app.errors import bp as errors_bp  #错误处理页面注册
    app.register_blueprint(errors_bp)

    return app
Exemple #7
0
def create_app(config_class=Config):
    app = Flask(__name__)
    # app.config['SECRET_KEY']='dai3hoahudhiuahduiah'
    # app.config['BABEL_DEFAULT_LOCALE'] = 'zh_Hans_CN'
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    bootstrap.init_app(app)
    babel.init_app(app)
    images.init_app(app)
    cache.init_app(app, config={'CACHE_TYPE': 'simple'})

    from app.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    from app.show import bp as show_bp
    app.register_blueprint(show_bp, url_prefix='/start')

    from app.contact import bp as contact_bp
    app.register_blueprint(contact_bp, url_prefix='/contact')

    from app.api import bp as api_bp
    api = Api(api_bp)
    api.add_resource(NgrokAPI, '/ngrok')
    app.register_blueprint(api_bp, url_prefix='/api')

    from app.main import bp as main_bp
    app.register_blueprint(main_bp)

    from app.data import bp as data_bp
    app.register_blueprint(data_bp, url_prefix='/data')

    from app.dashboard import bp as dashboard_bp
    app.register_blueprint(dashboard_bp)

    return app
Exemple #8
0
def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    bootstrap.init_app(app)
    babel.init_app(app)

    login.init_app(app)
    login.login_view = 'admin.login'

    configure_uploads(app, (photos, sphotos))
    patch_request_class(app)

    from app.admin import bp as admin_bp
    app.register_blueprint(admin_bp)

    from app.auth import bp as auth_bp
    from app.auth.routes import StuAPI, StuListAPI, We_Api

    api_stu = Api(auth_bp)

    api_stu.add_resource(StuListAPI, '/stu')
    api_stu.add_resource(StuAPI, '/stu/<id>')
    api_stu.add_resource(We_Api, '/weapi')
    app.register_blueprint(auth_bp)

    from app.main import bp as main_bp
    from app.main.routes import TaskAPI, TaskListAPI, OpenRes, MediaRes

    api_main = Api(main_bp)

    api_main.add_resource(TaskListAPI, '/tasks')
    api_main.add_resource(TaskAPI, '/tasks/<int:id>')
    api_main.add_resource(OpenRes, '/res')
    api_main.add_resource(MediaRes, '/media')

    app.register_blueprint(main_bp)

    from app.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    if not app.debug and not app.testing:
        # ...

        if app.config['LOG_TO_STDOUT']:
            stream_handler = logging.StreamHandler()
            stream_handler.setLevel(logging.INFO)
            app.logger.addHandler(stream_handler)
        else:
            if not os.path.exists('logs'):
                os.mkdir('logs')
            file_handler = RotatingFileHandler('logs/weapi.log',
                                               maxBytes=10240,
                                               backupCount=10)
            file_handler.setFormatter(
                logging.Formatter('%(asctime)s %(levelname)s: %(message)s '
                                  '[in %(pathname)s:%(lineno)d]'))
            file_handler.setLevel(logging.INFO)
            app.logger.addHandler(file_handler)

        app.logger.setLevel(logging.INFO)
        app.logger.info('*' * 45)
        app.logger.info('*' * 3 + '    ' * 3 + 'Weapp_API Startup' +
                        '   ' * 3 + '*' * 3)
        app.logger.info('*' * 45)

        try:
            app.logger.info('*' * 45)
            app.logger.info('*' * 3 + ' ' * 3 + app.config['SECRET_KEY'] +
                            '  ' * 3)
            app.logger.info('*' * 45)

        except KeyError:
            app.logger.info('*' * 45)
            app.logger.info('*' * 3 + '    ' * 3 + "GET ADMINS Failed" +
                            '   ' * 3)
            app.logger.info('*' * 45)

    return app
Exemple #9
0
#Extensões nativas do Flask
from flask import Flask, jsonify, request
#Extensões externas
from flask_sqlalchemy import SQLAlchemy
from dynaconf import FlaskDynaconf
#Outras extensões
import requests, os, click
#Factory's
from ext import database
from ext import configuration
from ext import commands
from ext import bootstrap
import blueprints.webui as webui
from blueprints.webui import form

app = Flask(__name__)
configuration.init_app(app)
database.init_app(app)
commands.init_app(app)
webui.init_app(app)
bootstrap.init_app(app)
form.init_app(app)