Open rafa-acioly opened 4 years ago
Any update?
Python interpreter uses __name__
variable to identify whether python file should be executed as a script or as a module. Everything under __name__ == "__main__"
block will be executed only when you call app.py directly from the command line (i.e as a script).
When you are calling gunicorn to execute an application, it imports the app.py as a module and all your blueprint configuration is not applied.
Not works even if it is outside
Please check the following code of the simplified application that covers the whole workflow:
# filename app.py
import flask
import flask_restx
APP = flask.Flask("some-app")
api_bp = flask.Blueprint("v1_api", __name__, url_prefix="/api/v1")
API = flask_restx.Api(api_bp)
APP.register_blueprint(api_bp)
NAMESPACE = flask_restx.Namespace("info")
@NAMESPACE.route("/")
class InfoAPI(flask_restx.Resource):
def get(self):
return "something"
API.add_namespace(NAMESPACE)
Should be executed as gunicorn -b localhost:8080 -w 4 app:APP
Code
Repro Steps (if applicable)
gunicorn -b localhost:8080 -w 4 run:app
localhost:8080/docs
Expected Behavior
When i start the app using
python run.py
the endpoints indocs
url are correct.Actual Behavior
When i start the ap using
gunicorn
thedocs
url do not show the endpointsEnvironment