Development Server

Starting with Flask 0.11 there are multiple built-in ways to run adevelopment server. The best one is the flask command line utilitybut you can also continue using the Flask.run() method.

Command Line

The flask command line script (Command Line Interface) is stronglyrecommended for development because it provides a superior reloadexperience due to how it loads the application. The basic usage is likethis:

  1. $ export FLASK_APP=my_application
  2. $ export FLASK_ENV=development
  3. $ flask run

This enables the development environment, including the interactivedebugger and reloader, and then starts the server onhttp://localhost:5000/.

The individual features of the server can be controlled by passing morearguments to the run option. For instance the reloader can bedisabled:

  1. $ flask run --no-reload

Note

Prior to Flask 1.0 the FLASK_ENV environment variable wasnot supported and you needed to enable debug mode by exportingFLASK_DEBUG=1. This can still be used to control debug mode, butyou should prefer setting the development environment as shownabove.

In Code

The alternative way to start the application is through theFlask.run() method. This will immediately launch a local serverexactly the same way the flask script does.

Example:

  1. if __name__ == '__main__':
  2. app.run()

This works well for the common case but it does not work well fordevelopment which is why from Flask 0.11 onwards the flaskmethod is recommended. The reason for this is that due to how the reloadmechanism works there are some bizarre side-effects (like executingcertain code twice, sometimes crashing without message or dying when asyntax or import error happens).

It is however still a perfectly valid method for invoking a non automaticreloading application.