def create_app(): from models.user import user_datastore app = Flask(__name__) app.config.from_object(config) db.init_app(app) mail.init_app(app) init_social(app, db.session) app.context_processor( _inject_processor) # register a template context processor function. _inject_template_global(app) _state = security.init_app(app, user_datastore, confirm_register_form=ExtendedRegisterForm, login_form=ExtendedLoginForm) security._state = _state app.security = security security.send_mail_task(_send_mail_task) app.register_blueprint(index.bp) # no `url_prefix` app.register_blueprint(account.bp) app.register_blueprint(social_auth) app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {'/api': api}) @app.teardown_request # register a func to be run at the end of each request, regardless of whether there was an exception or not. def teardown_request(exception): if exception: db.session.rollback() db.session.remove() return app
def create_app(): from models.user import user_datastore app = Flask(__name__) app.config.from_object(config) db.init_app(app) mail.init_app(app) app.context_processor(_inject_processor) _inject_template_global(app) _state = security.init_app(app, user_datastore, confirm_register_form=ExtendedRegisterForm, login_form=ExtendedLoginForm) security._state = _state app.security = security security.send_mail_task(_send_mail_task) app.register_blueprint(index.bp, url_prefix='/') app.register_blueprint(account.bp, url_prefix='/') @app.teardown_request def teardown_request(exception): if exception: db.session.rollback() db.session.remove() return app
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(): conf = get_config() app = Flask(__name__) app.config.update(conf['ENV'][os.getenv('ENV')]) db.init_app(app) mail.init_app(app) cache.init_app(app,config=conf['CACHE_CONFIG']) return app
def create_app(): app = Flask(__name__) app.config.from_object(config.DevelopmentConfig) api.init_app(app) db.init_app(app) mail.init_app(app) CORS(app) return app
def create_app(app: Flask): app.config.from_object(config) register_blueprint(app) db.init_app(app) mail.init_app(app) CORS(app) 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) 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_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) cache.init_app(app) db.init_app(app) db.app = app login_manager.init_app(app) mail.init_app(app) setup_themes(app) Mobility(app) from .utils.filters import register_filters register_filters(app) from .utils.processors import utility_processor app.context_processor(utility_processor) from .api import api as api_blueprint app.register_blueprint(api_blueprint, url_prefix='/api') from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .account import account as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/account') from .admins import admin admin.init_app(app) @app.route('/favicon.ico') def favicon(): return send_from_directory(app.static_folder, 'favicon.ico', mimetype='image/vnd.microsoft.icon') @app.route('/robots.txt') def robotstxt(): return send_from_directory(app.static_folder, 'robots.txt') # 暂时解决因Gunicorn中引发ERROR 11而无法正常提交的问题 #@app.teardown_request #def teardown_request(response_or_exc): # if app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']: # try: # db.session.commit() # except: # db.session.rollback() # db.session.remove() return app
def init_app(app): db.init_app(app) mail.init_app(app) debug_bar.init_app(app) _state = security.init_app( app, user_datastore, confirm_register_form=ExtendedRegisterForm, login_form=ExtendedLoginForm, ) security._state = _state app.security = security security.send_mail_task(send_mail)
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) db.init_app(app) db.app = app if not app.config['TESTING']: configure_custom_settings(app) config[config_name].init_app(app) thumbnail.init_app(app) babel.init_app(app) cache.init_app(app) login_manager.init_app(app) mail.init_app(app) setup_themes(app) Mobility(app) from .utils.filters import register_filters register_filters(app) from .utils.processors import utility_processor app.context_processor(utility_processor) from .api import api as api_blueprint app.register_blueprint(api_blueprint, url_prefix='/api') from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .account import account as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/account') from .admins import admin admin.init_app(app) @app.route('/favicon.ico') def favicon(): return send_from_directory(app.static_folder, 'favicon.ico', mimetype='image/vnd.microsoft.icon') @app.route('/robots.txt') def robotstxt(): return send_from_directory(app.static_folder, 'robots.txt') return app
def create_app(config_name): app = Flask(__name__) app.config['APPENV'] = str(get_appconfig()) app.config.from_object(config[config_name]) config[config_name].init_app(app) cache.init_app(app) db.init_app(app) db.app = app login_manager.init_app(app) mail.init_app(app) setup_themes(app) Mobility(app) from .utils.filters import register_filters register_filters(app) from .utils.processors import utility_processor app.context_processor(utility_processor) from .api import api as api_blueprint app.register_blueprint(api_blueprint, url_prefix='/api') from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .account import account as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/account') from .admins import admin admin.init_app(app) # 暂时解决因Gunicorn中引发ERROR 11而无法正常提交的问题 @app.teardown_request def teardown_request(response_or_exc): if app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']: try: db.session.commit() except: db.session.rollback() db.session.remove() 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
import os from flask import Flask from flask_migrate import Migrate from ext import database, cors, mail app = Flask(__name__) cors.init_app(app) mail.init_app(app) database.init_app(app) migrate = Migrate(app, database.db) from model.message import Message from blueprints.message import bp_message app.register_blueprint(bp_message)
from flask import Flask from flask_script import Manager from ext import mail app = Flask(__name__) app.config.from_pyfile('settings.py') mail.init_app(app) # 初始化邮件发送对象 manager = Manager(app) # 注册蓝图 from views import metoo from user import user app.register_blueprint(metoo) app.register_blueprint(user) if __name__ == '__main__': manager.run()