I want to use Flask blueprints to organize my Flask-Restful resources into separate url prefixes. Regardless of what url prefix I set (during either blueprint creation or registration), everything gets mapped to the raw route paths. How do I correctly use Restful with blueprints?
app = Flask(__name__)
api = Api(app)
api.add_resource(Building, '/<int:id>', endpoint='building')
api.add_resource(Jack, '/<int:id>', endpoint='jack')
building_api = Blueprint('building_api', __name__)
jack_api = Blueprint('jack_api', __name__)
You need to pass the blueprint to the
Api instance, not the app.
building_bp = Blueprint('buildings', __name__) building_api = Api(building_bp) building_api.add_resource(Building, '/<int:id>') app.register_blueprint(building_bp, url_prefix='/buildings')