looking for some solutions? You are welcome.

SOLVED: Flask RestPlus Api module has no attribute namespace

Aaron S.:

I am currently starting to learn the Flask RestPlus framework. I have the following code I started, but I cannot figure out why I keep getting this error below. I appreciate any help, thanks!

Stack Trace:

api_1  | Traceback (most recent call last):
api_1  |   File "/app/app.py", line 3, in <module>
api_1  |     from api.main.resources.healthResource import ns as health_resource_ns
api_1  |   File "/app/api/main/resources/healthResource.py", line 4, in <module>
api_1  |     ns = api.namespace('/health', description='API Health Resource')
api_1  | AttributeError: module 'app.api' has no attribute 'namespace'

Here is my code:

app.py

from flask import Flask, Blueprint
from flask_restplus import Api
from api.main.resources.healthResource import ns as health_resource_ns

app = Flask(__name__)
api = Api(version='1.0', title='flask-api-template',
          description='Flask RestPlus API Template Project')


def initialize_app(flask_app):
    blueprint = Blueprint('api', __name__, url_prefix='/api')

    api.init_app(blueprint)

    api.add_namespace(health_resource_ns)

    flask_app.register_blueprint(blueprint)


def run():
    initialize_app(app)
    app.run()


if __name__ == '__main__':
    run()

healthResource.py

from flask_restplus import Resource
from app import api

ns = api.namespace('/health', description='API Health Resource')


@ns.route("/")
class HealthResource(Resource):
    def get(self):
        return "Success"



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent