def register_extensions(app): db.init_app(app) bootstrap.init_app(app) moment.init_app(app) whooshee.init_app(app) loginmanager.init_app(app) mail.init_app(app)
def register_extensions(app): db.init_app(app) moment.init_app(app) csrf.init_app(app) bootstrap.init_app(app) login_manager.init_app(app) avatars.init_app(app)
def register_extensions(app): """ 扩展实例化 :param app: :return: """ db.init_app(app) moment.init_app(app) migrate.init_app(app=app, db=db) cache.init_app(app) login_manager.init_app(app) # 登录过滤保护 login_manager.exempt_views((user_bp, demo_bp, audio_bp, img_api_bp, ocr_api_bp)) session.init_app(app) csrf.init_app(app) # csrf过滤保护 csrf.exempt_views((demo_bp, audio_bp, img_api_bp, ocr_api_bp)) # 定时任务 解决FLASK DEBUG模式定时任务执行两次 if os.environ.get('FLASK_DEBUG', '0') == '0': scheduler.init_app(app) scheduler.start() elif os.environ.get('WERKZEUG_RUN_MAIN') == 'true': scheduler.init_app(app) scheduler.start()
def register_extensions(app): db.init_app(app) oauth.init_app(app) socketio.init_app(app) login_manager.init_app(app) csrf.init_app(app) moment.init_app(app)
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) mail.init_app(app) moment.init_app(app)
def register_extensions(app): toolbar.init_app(app) bootstrap.init_app(app) db.init_app(app) login_manager.init_app(app) moment.init_app(app) dropzone.init_app(app) whooshee.init_app(app)
def extension(app): csrf.init_app(app) moment.init_app(app) migrate.init_app(app) bootstrap.init_app(app) login_manager.init_app(app) db.init_app(app) return None
def register_extensions(app): bootstrap.init_app(app) db.init_app(app) login_manager.init_app(app) mail.init_app(app) dropzone.init_app(app) moment.init_app(app) whooshee.init_app(app) avatars.init_app(app) csrf.init_app(app)
def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) db.init_app(app) migrate.init_app(app, db) login.init_app(app) mail.init_app(app) bootstrap.init_app(app) moment.init_app(app) celery.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.scraping import bp as scraping_bp from app.scraping.scraper import Scraper from app.scraping import tasks app.register_blueprint(scraping_bp, url_prefix='/scraping') app.scrapers = { "rechem": tasks.rechem_routine_task, "test_task": tasks.test_task } 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/DNMS.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('DNMS startup') return app
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) db.init_app(app) login_manager.init_app(app) pagedown.init_app(app) flask_admin.init_app(app) configure_uploads(app, photos) patch_request_class(app) flask_admin.add_view(PostModelView(Post, db.session, name='博文管理')) flask_admin.add_view(UserModelView(User, db.session, name='用户管理')) flask_admin.add_view(RoleModelView(Role, db.session, name='身份管理')) path = os.path.join(os.path.dirname(__file__), 'static') flask_admin.add_view(MyFileAdmin(path, '/static', name='文件管理')) handler = logging.FileHandler('flask_error.log', encoding='UTF-8') handler.setLevel(logging.DEBUG) logging_format = logging.Formatter( '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s') handler.setFormatter(logging_format) app.logger.addHandler(handler) from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') from .api_1_0 import api as api_1_0_blueprint app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0') from .pic import pic as pic_blueprint app.register_blueprint(pic_blueprint, url_prefix='/pic') return app
def configure_extensions(app): pages.init_app(app) bootstrap.init_app(app) app.config["BOOTSTRAP_SERVE_LOCAL"] = True db.init_app(app) app.config["db"] = db login_manager.init_app(app) app.config['ext_login_manager'] = login_manager configure_identity(app) moment.init_app(app) mail.init_app(app) app.config['ext_mail'] = mail sendmail.init_app(app) app.config['contrib_sendmail'] = sendmail
def create_app(): app = Flask(__name__) app.config.from_object(Config) db.init_app(app) marshmallow.init_app(app) migrate.init_app(app, db) login.init_app(app) dynaconf.init_app(app) mail.init_app(app) moment.init_app(app) # configurando os blueprints accounts.configure(app) errors.configure(app) feed.configure(app) users.configure(app) #image.configure(app) email.configure(app) return app
def create_app(config_name): """ An flask application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/ Arguments: config_name: the key value if the config.config dict, e.g. 'dev', 'test', 'product', 'default' """ app = Flask(__name__) app.config.from_object(config[config_name]) # 首先调用配置对象的init_app config[config_name].init_app(app) # init SQLAlchemy db.init_app(app) # init Bcrypt bcrypt.init_app(app) # init LoginManager login_manager.init_app(app) # init Principal principal.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # Add the UserNeed to the identity if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) # Add each role to the identity if hasattr(current_user, 'roles'): for role in current_user.roles: identity.provides.add(RoleNeed(role.name)) # init DebugToolbarExtension debug_toolbar.init_app(app) # init Cache cache.init_app(app) # init Flask-Assets assets_env.init_app(app) assets_env.register("main_css", main_css) assets_env.register("main_js", main_js) # init Flask-Admin admin.init_app(app) admin.add_view(CustomView(name='Custom')) models = [User, Role, Comment, Tag] for model in models: admin.add_view(CustomModelView(model, db.session, category='Models')) # 单独处理Post model,因为我们自定了CustomModelView的自类PostView admin.add_view(PostView(Post, db.session, category='Models')) admin.add_view(CustomFileAdmin( os.path.join(os.path.dirname(__file__), 'static'), '/static/', name='Static Files' )) # init Flask-Bootstrap bootstrap.init_app(app) # init Flask-Mail mail.init_app(app) # init Flask-Moment moment.init_app(app) ############################################################################ # init RestApi rest_api.add_resource(PostApi, '/api/post', '/api/post/<int:post_id>', endpoint='api') rest_api.add_resource(AuthApi, '/api/auth') rest_api.init_app(app) # register blueprint app.register_blueprint(blog_blueprint) app.register_blueprint(main_blueprint) app.register_blueprint(auth_blueprint) # register api blueprint app.register_blueprint(api_blueprint) return app
def register_other(app): moment.init_app(app)
def register_extensions(app): csrf.init_app(app) db.init_app(app) migrate.init_app(app, db) moment.init_app(app)
# -*- coding: utf-8 -*-