def create_app(): app = Flask(__name__) app.config.from_object('settings') cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) api = Api(app) api.init_app(app) # init influxdb client influxdb.init_app(app) # init mongodb # mongodb.init_app(app) # init mysqldb mysqldb.init_app(app) # init Marshmallow ma.init_app(app) # register resources initialize_routes(api) return app
def create_app(self): application = Flask(config("APPLICATION_NAME")) application.config.from_pyfile("settings/test.py") from models import db, migrate db.init_app(application) migrate.init_app(application, db) from serializers import ma ma.init_app(application) from tasks import rq rq.init_app(application) from views import api_views, html_views application.register_blueprint(api_views) application.register_blueprint(html_views) from commands import CLI_COMMANDS for cli_name, cli_command in CLI_COMMANDS.items(): application.cli.add_command(cli_command, name=cli_name) return application
import os.path as op from flask import Flask from flask_restful import Api from models import db from serializers import ma from resources import ProductResource app = Flask(__name__) app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///main.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False api = Api(app) db.init_app(app) ma.init_app(app) db.create_all(app=app) if __name__ == '__main__': api.add_resource(ProductResource, '/api/product/') app.run(host='0.0.0.0', debug=True)