def create_app(): # instantiate the app app = BaseFlask(__name__) # configure interactive debugger if app.debug: app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True) # register extensions db.init_app(app) # register blueprints from project.views.index import blueprint as index_bp from project.views.api import blueprint as api_bp app.register_blueprint(index_bp) app.register_blueprint(api_bp, url_prefix='/api') # register commands from project.commands import cli app.cli.add_command(cli) # register error handlers from project.common import exceptions from project.common import error_handlers app.register_error_handler(exceptions.InvalidPayload, error_handlers.handle_exception) app.register_error_handler(exceptions.BusinessException, error_handlers.handle_exception) app.register_error_handler(exceptions.UnauthorizedException, error_handlers.handle_exception) app.register_error_handler(exceptions.ForbiddenException, error_handlers.handle_exception) app.register_error_handler(exceptions.NotFoundException, error_handlers.handle_exception) if not app.config['DEBUG']: # Thise handlers hide errors that help with debuging app.register_error_handler(exceptions.ServerErrorException, error_handlers.handle_exception) app.register_error_handler(Exception, error_handlers.handle_general_exception) return app
def extension(app): print('hi there') csrf.init_app(app) db.init_app(app) login_manager.init_app(app) moment.init_app(app) return None
def create_app(): app = Flask(__name__) config = os.environ.get('APP_SETTINGS', 'project.config.ProductionConfig') app.config.from_object(config) for bp in all_blueprints: import_module(bp.import_name) app.register_blueprint(bp) login_manager.login_view = "index.register" logging.config.dictConfig(app.config["LOG_CONFIG"]) if app.config.get('TESTING'): werkzeug_logger = logging.getLogger('werkzeug') werkzeug_logger.setLevel(logging.ERROR) csrf.init_app(app) toolbar.init_app(app) db.init_app(app) # FIXME: OMG Flask-SQLAlchemy doesn't set app instance when init_app() db.app = app login_manager.init_app(app) login_manager.user_loader(load_user) redis_store.init_app(app) oauth.init_app(app) cache.init_app(app, config={'CACHE_TYPE': 'redis'}) return app
def register_extensions(app): """Register Flask extensions.""" bcrypt.init_app(app) cache.init_app(app) db.init_app(app) csrf_protect.init_app(app) login_manager.init_app(app) debug_toolbar.init_app(app) migrate.init_app(app, db) # webpack.init_app(app) return None
def register_extensions(app): """Initialize Flask extensions.""" # Flask-SQLAlchemy db.init_app(app) # Flask-Migrate migrate.init_app(app, db) # Flask-User user_manager = UserManager(app, db, User, UserEmailClass=UserEmail) # Flask-Admin admin = Admin(app, name='Admin Dashboard', template_mode='bootstrap3') # Flask_Admin: Create custom model view class class RestrictedModelView(ModelView): # Display primary keys column_display_pk = True # Hide admin pages by overwriting Flask-Admin's is_accessible function def is_accessible(self): if not current_user.is_authenticated: return False return current_user.has_roles('admin') """ # Redirect to a page if the user doesn't have access def inaccessible_callback(self, name, **kwargs): # redirect to login page if user doesn't have access return redirect(url_for('user.register', next=request.url))""" # Flask-Admin: Add views admin.add_view(RestrictedModelView(User, db.session)) admin.add_view(RestrictedModelView(UserEmail, db.session)) admin.add_view(RestrictedModelView(Role, db.session)) admin.add_view(RestrictedModelView(UserRoles, db.session)) # Flask-Admin: Protect admin page @app.before_first_request def restrict_admin_url(): endpoint = 'admin.index' url = url_for(endpoint) admin_index = app.view_functions.pop(endpoint) @app.route(url, endpoint=endpoint) @roles_required('admin') def secure_admin_index(): return admin_index() # Flask-Mail mail.init_app(app) # Flask-WTF csrf_protect.init_app(app) return None
def create_app(): app = Flask(__name__) used_config = environ.get('APP_SETTINGS', 'config.Config') app.config.from_object(used_config) db.init_app(app) for bp in all_blueprints: import_module(bp.import_name) app.register_blueprint(bp) with app.app_context(): for module in app.config.get('DB_MODELS_IMPORT', list()): import_module(module) with app.app_context(): db.create_all() return app
def create_app(): app = Flask(__name__, static_url_path='/static') used_config = environ.get('APP_SETTINGS', 'config.ProductionConfig') app.config.from_object(used_config) with app.app_context(): for module in app.config.get('DB_MODELS_IMPORT', list()): import_module(module) for bp in all_blueprints: import_module(bp.import_name) app.register_blueprint(bp) logging.config.dictConfig(app.config["LOG_CONFIG"]) db.init_app(app) mail.init_app(app) celery.init_app(app) csrf.init_app(app) app.template_context_processors[None].append(inject_pagechunks) app.jinja_env.filters['strftime'] = datetime return app
def setup_extensions(app): db.init_app(app) bcrypt.init_app(app) migrate.init_app(app, db) mail.init_app(app)
from config import BaseConfig import os ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) ################ #### config #### ################ app = Flask(__name__) CORS(app) app.config['CORS_HEADERS'] = 'Content-Type' # CORS(app, resources={r"/*":{"origins":"*"}}) bcrypt = Bcrypt(app) login_manager = LoginManager() login_manager.init_app(app) app.config.from_object(BaseConfig) db.init_app(app) guard.init_app(app, User) from project.controllers.routes import routes_blueprint # register our blueprints app.register_blueprint(routes_blueprint) from project.models import User
def configure_extensions(app): db.init_app(app) login_manager.init_app(app) bootstrap.init_app(app)
def register_extensions(app): api.init_app(app) db.init_app(app) migrate.init_app(app, db)
def configure_extentions(app): db.init_app(app) moment.init_app(app) with app.test_request_context(): db.create_all()