You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromflaskimportFlaskfromflask_restximportApiapp=Flask(__name__)
# NB: moving this line after the `route('/')` definition makes it workapi=Api(app, version='1.0', title='MyAPI', doc='/api')
@app.route('/')defindex():
return'OK'app.run(debug=True)
Repro Steps (if applicable)
The provided code answers a 404 on a request on /
However, if the call to API() is done after the setting of the / route ,then things work as expected.
Expected Behavior
Requests to / should answer properly.
Actual Behavior
Requests to / answer with a 404.
Error Messages/Stack Trace
N/A
Environment
Python 3.10.8
Flask 2.2.3
Flask-RESTX 1.0.6
Additional Context
Already mentioned in #452 as a question, but seems more a bug.
The text was updated successfully, but these errors were encountered:
The issue is that this project uses the root view to build other URLs during API creation, therefore it must ensure the root view is created before the API is initialized to allow this to happen. As other users have pointed out, that is why it works correctly if you register the root view first.
Thanks @peter-doggart. I reached the render_root() while investigating, but from a user perspective, the final behavior was unexpected and needed some time to be narrowed down (hence the bug label).
I understand from the discussion that there is no simple way to go around this. Making it appear in the documentation would indeed be helpful to avoid users scratching their heads on this.
Minimal Code to reproduce issue
Repro Steps (if applicable)
404
on a request on/
However, if the call to
API()
is done after the setting of the/
route ,then things work as expected.Expected Behavior
Requests to
/
should answer properly.Actual Behavior
Requests to
/
answer with a404
.Error Messages/Stack Trace
N/A
Environment
Additional Context
Already mentioned in #452 as a question, but seems more a bug.
The text was updated successfully, but these errors were encountered: