def configure_extensions(app): from models import Anonymous import admin from flask_app import socket import commands db.init_app(app) migrate.init_app( app, db, render_as_batch=app.config["SQLALCHEMY_DATABASE_URI"].startswith( "sqlite:")) login.init_app(app) login.login_view = "main.index" login.login_message = None login.anonymous_user = Anonymous admin.init_app(app, db) mail.init_app(app) cors.init_app(app, resources={r"/*": { "origins": app.config["ALLOWED_URLS"] }}, supports_credentials=True) socket.init_app(app) commands.init_app(app)
def create_app(config=None) -> Flask: locale.setlocale(locale.LC_ALL, "pt_BR.UTF-8") # set locale app = Flask(__name__, static_folder="../static", template_folder="../templates") if config is None: config = default_config app.config.from_object(config) # Extensions db.init_app(app) migrate.init_app(app, db) ma.init_app(app) # Blueprints and Namespaces app = blueprints_factory.register_blueprints(app) api.init_app(app) """ loghandler = RotatingFileHandler(os.path.join(app.config.get("BASEDIR"), "logs", "partyou.log")) loghandler.setFormatter(Formatter( "%(asctime)s %(levelname)s: %(message)s " "[in %(pathname)s:%(lineno)d]" )) app.logger.addHandler(loghandler) app.logger.setLevel(logging.INFO) app = logger_factory.create_logger(app) """ return 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) moment.init_app(app) toolbar.init_app(app) migrate.init_app(app, db)
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) login.init_app(app) mail.init_app(app) bootstrap.init_app(app) moment.init_app(app) babel.init_app(app) app.elasticsearch = Elasticsearch([app.config['ELASTICSEARCH_URL']]) \ if app.config['ELASTICSEARCH_URL'] else None 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) 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('Microblog 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) 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
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
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
USER_DB = 'postgres' PASS_DB = 'admin' #URL_DB = '192.168.1.69' URL_DB = 'localhost' NAME_DB = 'mikauran_store' PORT = 5432 FULL_URL_DB = f'postgresql://{USER_DB}:{PASS_DB}@{URL_DB}:{PORT}/{NAME_DB}' app.config['SQLALCHEMY_DATABASE_URI'] = FULL_URL_DB app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #Configuracion de la Bd db.init_app(app) #Configure flask-migrate ma.init_app(app) migrate.init_app(app, db) # Api(app, catch_all_404s=True) app.url_map.strict_slashes = False app.register_blueprint(store_api_v1_bp) # # Registra manejadores de errores personalizados regErrors = RegisterErrors() regErrors.register_error_handlers(app) @app.route('/') def home(): app.logger.debug( "Inside Mikauran web admin dashboard and loading home.html")