Search code examples
pythonflaskflask-restplus

Flask route at / returns 404 when used with Flask-Restplus


I have a Flask app which has a Flask-RestPlus API as well as a "/" route. When I try to access "/" however, I get a 404. If I remove the Flask-RestPlus extension, the route works. How do I make both parts work together?

from flask import Flask
from flask_restplus import Api

app = Flask(__name__)
api = Api(app, doc="/doc/")  # Removing this makes / work

@app.route("/")
def index():
    return "foobar"

Solution

  • This is an open issue in Flask-RestPlus. As described in this comment on that issue, changing the order of the route and Api solves the issue.

    from flask import Flask
    from flask_restplus import Api
    
    app = Flask(__name__)
    
    @app.route("/")
    def index():
        return "foobar"
    
    api = Api(app, doc="/doc/")