Python Forum
Upgrade/Implement to FlaskRestPlus from Flask
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upgrade/Implement to FlaskRestPlus from Flask
#1
Hello everyone,

I am trying to add Flask RestPlus to a project that has worked heavily in only using Flask and FlaskCors

I have been trying to use RestPlus as a way to help us have swagger documentation but I am running into some issues

The main piece of code that instantiates everything is written as follows
def api_prefix(app):
    return f'/api/{app.config.get("API_VERSION", "v1")}'


def create_app() -> Flask:
    app = Flask(__name__, instance_relative_config=True)
    load_app_config(app)
    CORS(app, resources={'*': {'origins': app.config['CORS_ORIGINS']}})

    contentful_client.init_app(app)

 @app.route('/healthpoke')
    def healthpoke():
        return 'OUCH!', 200

    apis = [
       test_api,
        test2_api,
        test3_api,
    ]

    for api in apis:
        app.register_blueprint(api, url_prefix=api_prefix(app))

    # register root/standalone blueprints (self versioned)

    app.register_blueprint(test4_api)
    app.register_blueprint(test5_api)
    app.register_blueprint(test6_api)

    return app


app = create_app()
But when I try to use it with RestPlus, I run into issues with how it's all handled
    def create_app() -> Api:
        api = Flask(__name__, instance_relative_config=True)
        app = Api(app=api)
        load_app_config(app)
        CORS(app, resources={'*': {'origins': app.config['CORS_ORIGINS']}})

        api.init_app(app)
        contentful_client.init_app(app)

        @api.route('/healthpoke')
        def healthpoke():
            return 'OUCH!', 200
And when I try running, I get this error
Error:
AttributeError: Api does not have config attribute
Is there anything I should be looking for?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020