def create_app(): app = Flask(__name__) register_route(app) cache.init_app(app) db.init_app(app) return app
def create_app(config=None): app = Flask(__name__) if config is not None: app.config.from_object(config) db.init_app(app) from src.blueprint.catalog.routes import main_blueprint app.register_blueprint(main_blueprint) return app
def setup_app(app): """ Setup the app """ # Link db to app db.init_app(app) # LoginManager setup login_manager.login_view = 'auth.login_route' login_manager.init_app(app) # Create tables if they do not exist already with app.app_context(): db.create_all() seed() # Redirect root point to app context root app.add_url_rule('/', 'index', lambda: redirect(url_for('auth.login_route'))) # Initialize and configure OAuth2 config_oauth(app) # Register blueprints app.register_blueprint(restful_api, url_prefix=app.config['APP_ROOT']) app.register_blueprint(admin, url_prefix='/admin') app.register_blueprint(auth, url_prefix='/auth') app.register_blueprint(developer, url_prefix='/developers') app.register_blueprint(user, url_prefix='/users') # ... and namespaces api.add_namespace(oauth2_namespace, path='/oauth2') api.add_namespace(support_namespace, path='/support') # Additional configurations app.before_request_funcs[None] = [resource_authorization]
from src import db from src.app import create_app from src.config.dev import DevelopmentConfig dev_config = DevelopmentConfig() app = create_app(config=dev_config) db.init_app(app) @app.before_first_request def create_tables(): db.create_all() if __name__ == "__main__": app.run()
def setup_app(app): """Setup the app.""" # set app default logging to INFO app.logger.setLevel(logging.INFO) logging.getLogger('o365_notifications').addHandler( flask_logging.default_handler) logging.getLogger('o365_notifications').setLevel(logging.INFO) # link db to app db.init_app(app) # link api to app api.init_app(app) # link cache to app cache.init_app(app) with app.app_context(): # create tables if they do not exist already db.create_all() # make use of OAS3 schema converters openapi3_converters() # use app context to load namespaces, blueprints and schemas import src.resources.tickets from src.serialization.serializers.HttpError import HttpErrorSchema from src.serialization.serializers.jira.Issue import IssueSchema # initialize root blueprint bp = Blueprint('api', __name__, url_prefix=app.config['APPLICATION_CONTEXT']) # link api to blueprint api.init_app(bp) # register blueprints app.register_blueprint(bp) # link swagger to app swagger.init_app(app) # Redirect incomplete paths to app context root app.add_url_rule('/', 'index', lambda: redirect(url_for('flasgger.apidocs'))) subs = app.config['APPLICATION_CONTEXT'].split('/') for n in range(2, len(subs)): rule = '/'.join(subs[:n] + ['/']) app.add_url_rule(rule, ''.join(('index-', str(n - 1))), lambda: redirect(url_for('flasgger.apidocs'))) # define OAS3 base template swagger.template = flasgger.apispec_to_template( app=app, spec=APISpec(title=app.config['OPENAPI_SPEC']['info']['title'], version=app.config['OPENAPI_SPEC']['info']['version'], openapi_version=app.config['OPENAPI_SPEC']['openapi'], plugins=(MarshmallowPlugin(), ), basePath=app.config['APPLICATION_CONTEXT'], **app.config['OPENAPI_SPEC']), definitions=[HttpErrorSchema, IssueSchema]) # register cli commands app.cli.add_command(o365_cli)
''' @author: Jwang135 ''' from src.Parser import Parser from flask import render_template from flask import Flask, request from flask.ext.mongoengine import MongoEngine from src.comment import Comment from src import db from mongoengine.errors import ValidationError from bson.objectid import ObjectId app = Flask(__name__) app.config.from_object('src.configue') db.init_app(app) projects = Parser.svn_list_parser('Data/svn_list.xml') Parser.svn_log_parse('Data/svn_log.xml',projects) # Learn from https://github.com/mukichou/cs242-1 and xyu37 @app.route('/') def home_page(): return render_template('index.html',projects=projects) @app.route('/mp1') def assignment_page(name=None): return render_template('projects.html', projects=projects,