I have a very simple Flask app (from https://flask.palletsprojects.com/en/stable/quickstart/)
# File name: app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
print("your server is running at:", "<Insert code here>")
I am using commands like flask run --host 127.0.0.1 --port 8200 to run my app server. I am trying to access the IP and port the development is listening to from the last line of the Python code. Is it possible? How should I do it?
What I am looking for:
$ flask run --host 127.0.0.1 --port 8200
your server is running at: http://127.0.0.1:8200
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:8200
Press CTRL+C to quit
The first line is printed by my code. The rest of lines are printed by Werkzeug.
printline, the server isn't running yet. At the very least you'd need to create some callback or middleware which is invoked by the server if and when it's running.