New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
route use “/” return 404 #712
Comments
The code above looks like pure Flask and not flask-restplus. There a few things to consider:
returns
Now, adding in all the flask-restplus info and trying
Couple big points above:
swagger.json and
however when hitting
I'll need to dig around a bit. I don't recall any issues with |
I've also done some digging and have found the source of the problem (still thinking of the best solution though) in flask-restplus/flask_restplus/api.py Line 253 in a48acaa
This is to allow the documentation to be served at the default In this case, flask-restplus/flask_restplus/api.py Line 366 in a48acaa
@j5awry if you change your example to remove the As for a solution, I'm going to have a think and hopefully come up with something over the weekend. Suggestions are welcomed! 😄 |
The root view is needed, even if it by default it just flask-restplus/flask_restplus/api.py Line 254 in a48acaa
Api._init_app() is called (where the root route is currently registered from). Lazily registering the root route using Flask's before_first_request signal works:
# Api._init_app
app.before_first_request(partial(self._register_root, self.blueprint or app)) However, this means the root endpoint is technically not available until after a request has been made. Attempting to build a URL for it using Still thinking on this one 🤔 |
Hi did anyone find a solution to this? Thanks! |
While writting this, found the same solution in a comment on another issue But why will I just erase my comment, right? Here it is: from flask import Flask
from flask_restx import Api
app: Flask = Flask(__name__)
@app.route("/")
def welcome():
return "Welcome!"
api = Api(app, doc="/doc/")
if __name__ == "__main__":
app.run() Important steps were:
Note, that docs do not display that endpoint, but you can fool them: # Can be placed anywhere
# Even in a different file and then imported to the main one
from flask_restx import Namespace, Resource
base_namespace = Namespace("base", path="/")
@base_namespace.route("/")
class Test(Resource):
@base_namespace.response(200, "A welcome response")
def get(self):
pass # whatever you put here won't work # after api initialization
api.add_namespace(base_namespace) |
***** BEFORE LOGGING AN ISSUE *****
Code
Repro Steps (if applicable)
Expected Behavior
A description of what you expected to happen.
Actual Behavior
A description of the unexpected, buggy behavior.
Error Messages/Stack Trace
If applicable, add the stack trace produced by the error
Environment
Additional Context
This is your last chance to provide any pertinent details, don't let this opportunity pass you by!
The text was updated successfully, but these errors were encountered: