Note: Before running any of the mentioned CLI commands, be sure to cd
to your project's root directory.
By default, Flask:
- expects your server code in
app.py
orwsgi.py
, - runs on port
5000
, and - does not run in
debug
mode.
If you're ok with these defaults, then you can simply do flask run
to start the server.
You can also run with some different settings like this:
flask --app my_flask_app.py --debug run --host 0.0.0.0 --port 6000
This command works for flask>=2.2
- for older Flask versions, do this instead:
FLASK_APP=my_flask_app.py FLASK_DEBUG=1 flask run --host 0.0.0.0 --port 6000
You can also start the Flask server directly in your Python code like this:
from flask import Flask
app = Flask(__name__)
# Add some router endpoints here...
# app.run() # Run with default settings
app.run(host='0.0.0.0', port=5000, debug=True)