Development Server
Warning
Do not use the development server when deploying to production. It is intended for use only during local development. It is not designed to be particularly efficient, stable, or secure.
See Deploying to Production for deployment options.
The flask run
CLI command is the recommended way to run the development server. Use the --app
option to point to your application, and the --debug
option to enable debug mode.
If another program is already using port 5000, you’ll see an OSError
when the server tries to start. It may have one of the following messages:
OSError: [Errno 98] Address already in use
Either identify and stop the other program, or use flask run --port 5001
to pick a different port.
netstat
(Linux)lsof
(macOS / Linux)netstat
(Windows)
> netstat -ano | findstr 5000
TCP 127.0.0.1:5000 0.0.0.0:0 LISTENING 6847
macOS Monterey and later automatically starts a service that uses port 5000. To disable the service, go to System Preferences, Sharing, and disable “AirPlay Receiver”.
Deferred Errors on Reload
When using the flask run
command with the reloader, the server will continue to run even if you introduce syntax errors or other initialization errors into the code. Accessing the site will show the interactive debugger for the error, rather than crashing the server.
If a syntax error is already present when calling flask run
, it will fail immediately and show the traceback rather than waiting until the site is accessed. This is intended to make errors more visible initially while still allowing the server to handle errors on reload.
In Code
Place the call in a main block, otherwise it will interfere when trying to import and run the application with a production server later.