Flask Local Development Guide
Run lightweight Python web applications and APIs using Flask on localhost:5000.
Flask is a lightweight web framework for Python, suitable for APIs, prototyping, and small sites. The built-in development server defaults to http://localhost:5000.
Quick Start
python -m venv .venv
source .venv/bin/activate
pip install flaskapp.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello from Flask on localhost'
if __name__ == '__main__':
app.run(debug=True)python app.pyAccess http://localhost:5000.
Change Port
app.run(host='0.0.0.0', port=8080, debug=True)Or use environment variables / Flask CLI:
flask --app app run --port 8000Comparison with Django / FastAPI
| Framework | Default Port | Features |
|---|---|---|
| Flask | 5000 | Microframework, flexible |
| Django | 8000 | Full-stack, Admin |
| FastAPI | 8000 | Asynchronous API, OpenAPI |
Production Notes
The built-in server is for development only; for production, use Gunicorn/uWSGI + Nginx (see our gunicorn article).
Frequently Asked Questions
Port 5000 Conflict on macOS
macOS AirPlay Receiver may occupy port 5000; change port=5001 or disable AirPlay receiving.
Debug Modedebug=True enables hot reloading; ensure it is turned off in production.
Summary
Flask local development defaults to http://localhost:5000, and can be started with just a few lines of code, making it suitable for rapid validation of Python APIs.