Change Port in Flask app (original) (raw)
Last Updated : 29 May, 2026
Flask runs on port 5000 by default, but the port can be changed by specifying a different port while running the application. This is useful when the default port is already in use or when multiple applications are running on the same system.
Port can be changed by passing the port parameter in the app.run() method:
app.run(port=8001)
It can also be combined with debug mode:
app.run(debug=True, port=8001)
**Example: This example creates a Flask app and runs it on port 8001 instead of the default port.
Python `
from flask import Flask app = Flask(name)
@app.route("/") def hello_world(): return "
Hello, World!
"if name == 'main': app.run(debug=True, port=8001)
`
**Output: Application will run on http://127.0.0.1:8001/
Port number is 8001
Flask app
**Explanation:
- Flask(__name__) creates the application instance
- @app.route("/") defines the home route
- app.run(debug=True, port=8001) runs the app in debug mode on port 8001