def create_app(config): app = Flask(__name__) app.config.from_object(config) app.register_blueprint(author_routes, url_prefix='/api/authors') app.register_blueprint(book_routes, url_prefix='/api/books') app.register_blueprint(user_routes, url_prefix='/api/users') SWAGGER_URL = '/api/docs' swaggerui_blueprint = get_swaggerui_blueprint( '/api/docs', '/api/spec', config={'app_name': "Flask Author DB"}) app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL) @app.route('/avatar/<filename>') def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) @app.after_request def add_header(response): return response @app.errorhandler(400) def bad_request(e): logging.error(e) return response_with(resp.BAD_REQUEST_400) @app.errorhandler(500) def server_error(e): logging.error(e) return response_with(resp.SERVER_ERROR_500) @app.errorhandler(404) def not_found(e): logging.error(e) return response_with(resp.SERVER_ERROR_404) @app.route('/api/spec') def spec(): swag = swagger(app, prefix='/api') swag['info']['base'] = "http://localhost:5000" swag['info']['version'] = "1.0" swag['info']['title'] = "Flask Author DB" return jsonify(swag) jwt = JWTManager(app) mail.init_app(app) db.init_app(app) with app.app_context(): db.create_all() logging.basicConfig( stream=sys.stdout, format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s', level=logging.DEBUG) return app
def create_app(config): app = Flask(__name__) app.config.from_object(config) app.register_blueprint(author_routes, url_prefix='/api/authors') app.register_blueprint(book_routes, url_prefix='/api/books') app.register_blueprint(user_routes, url_prefix='/api/users') @app.route('/avatar/<filename>') def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_ FOLDER'],filename) jwt = JWTManager(app) mail.init_app(app) db.init_app(app) with app.app_context(): db.create_all() # START GLOBAL HTTP CONFIGURATIONS @app.after_request def add_header(response): return response @app.errorhandler(400) def bad_request(e): logging.error(e) return response_with(resp.BAD_REQUEST_400) @app.errorhandler(500) def server_error(e): logging.error(e) return response_with(resp.SERVER_ERROR_500) @app.errorhandler(404) def not_found(e): logging.error(e) return response_with(resp.SERVER_ERROR_404) @app.route("/api/spec") def spec(): swag = swagger(app, prefix='/api') swag['info']['base'] = "http://localhost:5000" swag['info']['version'] = "1.0" swag['info']['title'] = "Flask Author DB" return jsonify(swag) swaggerui_blueprint = get_swaggerui_blueprint('/api/docs', '/api/spec', config={'app_name': "Flask Author DB"}) app.register_blueprint(swaggerui_blueprint, url_prefix='/api/docs') return app
def create_app(config): # that is skeleton of main app = Flask(__name__) app.register_blueprint(author_routes, url_prefix='/api/authors') app.register_blueprint(book_routers, url_prefix='/api/books') app.register_blueprint(user_routers, url_prefix='/api/users') app.config.from_object(config) # START GLOBAL HTTP CONFIGURATION @app.after_request def add_header(response): return response @app.errorhandler(400) def bad_request(e): logging.error(e) return response_with(resp.BAD_REQUEST_400) @app.errorhandler(500) def server_error(e): logging.error(e) return response_with(resp.SERVER_ERROR_500) @app.errorhandler(404) def not_found(e): logging.error(e) return response_with(resp.SERVER_ERROR_404) @app.route('/avatar/<filename>') def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) db.init_app(app) jwt = JWTManager(app) mail.init_app(app) dashboard.bind(app) with app.app_context(): db.create_all() logging.basicConfig(stream=sys.stdout, format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s', level=logging.DEBUG) return app
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) jwt.init_app(app) db.init_app(app) mail.init_app(app) from api.routes.users import user_routes app.register_blueprint(user_routes, url_prefix='/api/users') from api.routes.authors import author_routes app.register_blueprint(author_routes, url_prefix='/api/authors') from api.routes.books import book_routes app.register_blueprint(book_routes, url_prefix='/api/books') return app
def create_app(app_config): app = Flask(__name__) app.config.from_object(app_config) #routes app.register_blueprint(customer_routes, url_prefix='/api/customers') app.register_blueprint(user_routes, url_prefix='/api/users') #route for upload photo @app.route('/photo/<filename>') def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) jwt = JWTManager(app) db.init_app(app) ma.init_app(app) mail.init_app(app) with app.app_context(): db.create_all() return app
logging.error(e) return response_with(resp.SERVER_ERROR_500) @app.errorhandler(404) def not_found(e): logging.error(e) return response_with(resp.SERVER_ERROR_404) @app.route('/avatar/<filename>', methods=['GET']) def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) # to use JWT for authorization jwt = JWTManager(app) mail.init_app(app) db.init_app(app) with app.app_context(): db.create_all() ''' def create_app(config): app = Flask(__name__) app.config.from_object(config) db.init_app(app) with app.app_context(): db.create_all() return app '''