Closed mostermann96 closed 2 years ago
I like to define the main routes outside of the api docs definition itself and import it to be used by Swagger.
First you import your "main" method:
from routes.user import do_login
Then you define your namespace like:
users_namespace = api.namespace(name="Users",
path="/user",
uri="",
description="Users related actions")
Then you call your "main" routes like:
@users_namespace.route("/login")
class Login(Resource):
@users_namespace.doc("")
@users_namespace.response(200, "OK Call")
@users_namespace.response(404, "Password error")
@users_namespace.response(400, "Bad Request error")
def post(self):
return do_login()
@users_namespace.response(200, "")
def options(self):
return ""
Thanks for the advice. With help from the Flask Discord, I figured out that the issue was starting the Flask server from PyCharm with an incorrect project structure. This apparently caused init_app()
to be skipped, resulting in my issues. Fixed it by following Flask's tutorial for project layouts.
I'm trying to get started with a more complex project structure in flask-restx and adding the endpoints with namespaces. However, after following the example, more complex tutorials or other basic tutorials, I still only receive 404s when calling get on /api or the endpoints I tried to define. My app.py looks as follows:
and the endpoint I tried to define:
The /site-map works and shows what I expect, after only receiving 404s from /api or /api/test , that only /site-map is an available endpoint. A pointer to my mistake would be greatly appreciated.