Пример #1
0
def create_app():
    app = Flask(__name__)
    # app.config['CELERY_IMPORTS'] = ('backgroundtask.add', )
    # app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
    # app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
    app.config.from_object(Config)
    app.config.from_object(TaskConifg)
    Config.init_app(app)
    # app.config['SESSION_TYPE'] = 'filesystem'
    # app.config['SESSION_FILE_DIR'] = tempfile.gettempdir()
    # app.permanent_session_lifetime = datetime.timedelta(days=1)
    # sess.init_app(app)
    moment.init_app(app)
    db.app = app
    db.init_app(app)
    login_manager.init_app(app)
    # celery.init_app(app)

    from .main import main as main_blueprint
    from .cimiss import cimiss as cimiss_blueprint
    from .product import product as product_blueprint
    from .page2 import page2 as page2_blueprint

    app.register_blueprint(main_blueprint)
    app.register_blueprint(cimiss_blueprint, url_prefix='/cimiss')
    app.register_blueprint(product_blueprint, url_prefix='/product')
    app.register_blueprint(page2_blueprint, url_prefix='/page2')
    socketio.init_app(app,
                      async_mode='eventlet',
                      message_queue=Basic.SOCKET_RMQ + '/socketio')

    scheduler.init_app(app)
    scheduler.start()
    return app
Пример #2
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)
Пример #3
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
Пример #4
0
from User.views import bbs
from ext import db, moment, photos

app = Flask(__name__)
app.config.from_pyfile('settings.py')

manager = Manager(app)

# 注册蓝图
app.register_blueprint(bbs)
app.register_blueprint(user)
app.register_blueprint(admin)

# 初始化对象
db.init_app(app)
moment.init_app(app)

# 数据库迁移
Migrate(app=app, db=db)
manager.add_command('db', MigrateCommand)

# 配置文件上传对象
configure_uploads(app, photos)
# 若设置为None,则以MAX_CONTENT_LENGTH配置为准
patch_request_class(app, size=None)


@app.route('/')
def hello_world():
    return redirect('/index/')