def create_app(config): app = Flask(__name__) app.config.from_object(app_config) db.init_app(app) with app.app_context(): db.create_all() @app.after_request def add_header(response): return response @app.errorhandler(400) def bad_request(e): return response_with(resp.BAD_REQUEST_400) @app.errorhandler(500) def server_error(e): return response_with(resp.SERVER_ERROR_500) @app.errorhandler(404) def not_found(e): return response_with(resp.SERVER_ERROR_404) app.register_blueprint(author_routes, url_prefix='/api/authors') app.register_blueprint(book_routes, url_prefix='/api/books') return app
def create_app(config): app = Flask(__name__) app.config.from_object(app_config) app.register_blueprint(category_routes, url_prefix='/api/categories') app.register_blueprint(product_routes, url_prefix='/api/products') # 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) db.init_app(app) with app.app_context(): db.create_all() return app
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
def create_app(config): app = Flask(__name__) CORS(app) app.config.from_object(config) app.register_blueprint(route_path_general, url_prefix='/api') # 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.NOT_FOUND_HANDLER_404) @app.errorhandler(AuthRequired) def auth_required(e): logging.error(e) return response_with(resp.UNAUTHORIZED_403, message=e.message) @app.errorhandler(DecodeError) def decode_error(e): logging.error(e) return response_with(resp.UNAUTHORIZED_403, message=e.message) @app.errorhandler(ExpiredSignatureError) def expired_error(e): logging.error(e) return response_with(resp.UNAUTHORIZED_403, message=e.message) @app.errorhandler(BaseJWTError) def base_jwt_error(e): logging.error(e) return response_with(resp.UNAUTHORIZED_403, message=e.message) # END GLOBAL HTTP CONFIGURATIONS db.init_app(app) with app.app_context(): # from api.models import * 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 setup(flask_app, with_login_manager=False): flask_app.config['SECRET_KEY'] = '@##&6cweafhv3426445' flask_app.config['SQLALCHEMY_DATABASE_URI'] = POSTGRES_URL flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False flask_app.config['TESTING'] = True db.init_app(flask_app) @flask_app.teardown_request def remove_db_session(exc): try: db.session.remove() except AttributeError: pass flask_app.app_context().push() import_models() if with_login_manager: from flask_login import LoginManager flask_app.config['SESSION_COOKIE_HTTPONLY'] = not flask_app.config['TESTING'] flask_app.config['SESSION_COOKIE_SECURE'] = False flask_app.config['REMEMBER_COOKIE_HTTPONLY'] = not flask_app.config['TESTING'] if not flask_app.config['TESTING']: flask_app.config['PERMANENT_SESSION_LIFETIME'] = 90 * 24 * 3600 flask_app.config['REMEMBER_COOKIE_DURATION'] = 90 * 24 * 3600 flask_app.config['REMEMBER_COOKIE_SECURE'] = True login_manager = LoginManager() login_manager.init_app(flask_app) import api.utils.login_manager if IS_APP or IS_WORKER: from api.utils.celery import CELERY_APP ApiHandler.set_celery(CELERY_APP, flask_app)
def init_db(app): """ init db and create all tables """ db.init_app(app) with app.app_context(): db.create_all()
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(test_config=None): # 1) app = Flask(__name__) if os.environ.get('WORK_ENV') == 'PROD': app_config = ProductionConfig elif os.environ.get('WORK_ENV') == 'TEST': app_config = TestingConfig else: app_config = DevelopmentConfig app.config.from_object(app_config) 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) # END GLOBAL HTTP CONFIGURATIONS @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) app.register_blueprint(product_routes, url_prefix='/api/products') swaggerui_blueprint = get_swaggerui_blueprint( '/api/docs', '/api/spec', config={'app_name': "Flask Author DB"}) app.register_blueprint(swaggerui_blueprint, url_prefix=swaggerui_blueprint.url_prefix) jwt = JWTManager(app) return app
def create_app(config): app = Flask(__name__) app.config.from_object(config) app.register_blueprint(route_path_countries, url_prefix=url_prefix) app.register_blueprint(route_path_locations, url_prefix=url_prefix) app.register_blueprint(route_path_panels, url_prefix=url_prefix) app.register_blueprint(route_path_target_groups, url_prefix=url_prefix) # 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.NOT_FOUND_HANDLER_404) # END GLOBAL HTTP CONFIGURATIONS @app.route("/api/spec") def spec(): swag = swagger(app, prefix=url_prefix) swag['info']['version'] = "1.0" swag['info'][ 'title'] = "Flask powered by API, Alchemy and Marshmallow 'devtest' showcase" return jsonify(swag) db.init_app(app) with app.app_context(): # from api.models import * 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): """ This function is responsible of create the app instance in with the parameters provided in the config file. """ app = Flask(__name__) app.config.from_object(config) db.init_app(app) with app.app_context(): db.create_all() return app
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) patch_request_class(app, 10 * 1024 * 1024) # 10MB max image size upload configure_uploads(app, IMAGE_SET) db.init_app(app) ma.init_app(app) jwt.init_app(app) api = Api(app) initialize_routes(api) return app
def create_app(config): app = Flask(__name__) app.config.from_object(config) app.register_blueprint(route_path_general, url_prefix='/api') app.register_blueprint(picture_blueprint) mongo = PyMongo(app) # 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.NOT_FOUND_HANDLER_404) # END GLOBAL HTTP CONFIGURATIONS @app.route("/api/v1.0/spec") def spec(): swag = swagger(app, prefix='/api/v1.0') swag['info']['version'] = "1.0" swag['info']['title'] = "Flask Starter API" return jsonify(swag) db.init_app(app) with app.app_context(): # from api.models import * 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): # 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(config): app = Flask(__name__) app.config.from_object(config) app.register_blueprint(route_path_drivers) app.register_blueprint(route_path_cars) # 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.NOT_FOUND_HANDLER_404) # END GLOBAL HTTP CONFIGURATIONS db.init_app(app) #with app.app_context(): # from api.models import * # db.create_all() logging.basicConfig( stream=sys.stdout, format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s', level=logging.DEBUG) migrate.init_app(app, db) ma.init_app(app) return app
def create_app(config_name): app = Flask(__name__, instance_relative_config=True) CORS(app, supports_credentials=True) app.config.from_object(app_config[config_name]) app.config.from_pyfile('config.py') db.init_app(app) @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.NOT_FOUND_HANDLER_404) @app.route('/api/v1.0/spec') def spec(): swag = swagger(app, prefix='/api/v1.0') swag['info']['version'] = '1.0' swag['info']['title'] = 'Flask Sample Api' return jsonify(swag) logging.basicConfig( stream=sys.stdout, format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s', level=logging.DEBUG) from api.api_v1 import api as api_blueprint app.register_blueprint(api_blueprint, url_prefix='/api/v1') return app
def create_app(config): app = Flask(__name__) app.config.from_object(config) app.register_blueprint(route_path_general, url_prefix='/api') # START GLOBAL HTTP CONFIGURATIONS @app.after_request def add_header(response): response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS') 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.NOT_FOUND_HANDLER_404) db.init_app(app) with app.app_context(): # from api.models import * 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(): app = Flask(__name__) app.config.from_object(app_config) db.init_app(app) with app.app_context(): db.create_all() app.register_blueprint(author_routes, url_prefix='/api/authors') app.register_blueprint(user_routes, url_prefix='/api/users') @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) jwt = JWTManager(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(): UPLOAD_FOLDER = './uploads' app = Flask(__name__) app.config['UPLOAD_FOLDER']= UPLOAD_FOLDER basedir = os.path.abspath(os.path.dirname(__file__)) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir, 'db.sqlite') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) with app.app_context(): db.create_all() # app.config.from_object(app_config) app.register_blueprint(posts_routes, url_prefix='/api/post') app.register_blueprint(comment_routes, url_prefix='/api/comments') @app.route('/image/<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) logging.basicConfig(stream=sys.stdout, format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(messages)s', level=logging.DEBUG) @app.route('/') def index(): return "<h1>Index route test</h1>" 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
@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 '''
from api.utils.database import db from api.routes.routes import limiter from api.routes.routes import route_page from flask import Flask from api.utils.config import DevelopmentConfig, ProductionConfig app = Flask(__name__) app.config.from_object(DevelopmentConfig) app.register_blueprint(route_page) db.init_app(app) db.app = app db.create_all() limiter.init_app(app)
def create_app(test_config=None): # 1) app = Flask(__name__) app_config = Config app.config.from_object(app_config) db.init_app(app) with app.app_context(): db.create_all() @app.route("/test/insert-post", methods=["GET", "POST"]) def add_post(): py = Category(id=1, name="hennie") p = Post(title='Snakes2', body='Ssssssss2', category_id=py.id) # py.posts.append(p) db.session.add(p) db.session.commit() return "success" @app.route("/test/insert-category", methods=["GET"]) def get_category(): category1 = Category(id=6, name="checkcommit") db.session.add(category1) db.session.commit() return "success" @app.route("/test/get-all-post", methods=["GET"]) def get_post(): res1 = Post.query.all() res2 = Post.query.get(2) print(res2) return "success" # @app.route("/test/add" , methods=["GET"]) # def add_user(): # User1 = User(username="******",email="pulovelty@nav" , password="******") # User1.create() # return "success" # # # # # @app.route("/test/get-all",methods=["GET"]) # def get_users(): # res1= User.query.all() # # return "success" # # @app.route("/test/get-detail",methods=["GET"]) # def get_detail(): # # res1 = User.query.filter_by(id =2) # print(res1 is None) # for elm in res1: # print(elm.username) # # res2 = User.query.order_by(User.username).all() # res3 = User.query.limit(1).all() # res4 = User.query.get(2) # # print("res2 :" , res2) # print("res3 :" , res3) # print("res4 : ", res4) # return "success" # # @app.route('/test/user/<username>') # def show_user(username): # # user = User.query.filter_by(username=username).all() # # if len(user)==0: # return "fail" # # return "success" @app.route("/") def main(): return "pong" return app