rewrite the development server docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 240a110 · Browse files · 3 files·+64 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+64 added−37 removed
- other:+64 added−37 removed
Provenance
- Commit
a671e47- Tree
c606773- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
240a110
3 files changed+64 added−37 removed
modified:docs/quickstart.rst+3 added-3 removed
106 unmodified lines107 108 Versions of Flask older than 0.11 use to have different ways to start the109 application. In short, the :command:`flask` command did not exist, and110 neither did :command:`python -m flask`. In that case you have two options:111-either upgrade to newer Flask versions or have a look at the :ref:`server`112-docs to see the alternative method for running a server.111+either upgrade to newer Flask versions or have a look at :doc:`/server`112+to see the alternative method for running a server.113 114 Invalid Import Name115 ```````````````````116 35 unmodified lines152 153 You can also control debug mode separately from the environment by154 exporting ``FLASK_DEBUG=1``.155 156-There are more parameters that are explained in the :ref:`server` docs.156+There are more parameters that are explained in :doc:`/server`.157 158 .. admonition:: Attention159 160 Even though the interactive debugger does not work in forking environments740 unmodified linesmodified:docs/server.rst+60 added-33 removed
1-.. _server:1+.. currentmodule:: flask2 3 Development Server4 ==================5 6-.. currentmodule:: flask6+Flask provides a ``run`` command to run the application with a7+development server. In development mode, this server provides an8+interactive debugger and will reload when code is changed.9 8-Starting with Flask 0.11 there are multiple built-in ways to run a9-development server. The best one is the :command:`flask` command line utility10-but you can also continue using the :meth:`Flask.run` method.10+.. warning::11 12+ Do not use the development server when deploying to production. It13+ is intended for use only during local development. It is not14+ designed to be particularly efficient, stable, or secure.15+16+ See :doc:`/deploying/index` for deployment options.17+18 Command Line19 ------------20 15-The :command:`flask` command line script (:ref:`cli`) is strongly16-recommended for development because it provides a superior reload17-experience due to how it loads the application. The basic usage is like18-this::21+The ``flask run`` command line script is the recommended way to run the22+development server. It requires setting the ``FLASK_APP`` environment23+variable to point to your application, and ``FLASK_ENV=development`` to24+fully enable development mode.25 26+.. code-block:: text27+20- $ export FLASK_APP=my_application28+ $ export FLASK_APP=hello29 $ export FLASK_ENV=development30 $ flask run31 32 This enables the development environment, including the interactive33 debugger and reloader, and then starts the server on26-*http://localhost:5000/*.34+http://localhost:5000/. Use ``flask run --help`` to see the available35+options, and :doc:`/cli` for detailed instructions about configuring36+and using the CLI.37 28-The individual features of the server can be controlled by passing more29-arguments to the ``run`` option. For instance the reloader can be30-disabled::31-32- $ flask run --no-reload33-38 .. note::39 36- Prior to Flask 1.0 the :envvar:`FLASK_ENV` environment variable was37- not supported and you needed to enable debug mode by exporting40+ Prior to Flask 1.0 the ``FLASK_ENV`` environment variable was not41+ supported and you needed to enable debug mode by exporting42 ``FLASK_DEBUG=1``. This can still be used to control debug mode, but43 you should prefer setting the development environment as shown44 above.45 46+47+Lazy or Eager Loading48+~~~~~~~~~~~~~~~~~~~~~49+50+When using the ``flask run`` command with the reloader, the server will51+continue to run even if you introduce syntax errors or other52+initialization errors into the code. Accessing the site will show the53+interactive debugger for the error, rather than crashing the server.54+This feature is called "lazy loading".55+56+If a syntax error is already present when calling ``flask run``, it will57+fail immediately and show the traceback rather than waiting until the58+site is accessed. This is intended to make errors more visible initially59+while still allowing the server to handle errors on reload.60+61+To override this behavior and always fail immediately, even on reload,62+pass the ``--eager-loading`` option. To always keep the server running,63+even on the initial call, pass ``--lazy-loading``.64+65+66 In Code67 -------68 45-The alternative way to start the application is through the46-:meth:`Flask.run` method. This will immediately launch a local server47-exactly the same way the :command:`flask` script does.69+As an alternative to the ``flask run`` command, the development server70+can also be started from Python with the :meth:`Flask.run` method. This71+method takes arguments similar to the CLI options to control the server.72+The main difference from the CLI command is that the server will crash73+if there are errors when reloading.74 49-Example::75+``debug=True`` can be passed to enable the debugger and reloader, but76+the ``FLASK_ENV=development`` environment variable is still required to77+fully enable development mode.78 51- if __name__ == '__main__':52- app.run()79+Place the call in a main block, otherwise it will interfere when trying80+to import and run the application with a production server later.81 54-This works well for the common case but it does not work well for55-development which is why from Flask 0.11 onwards the :command:`flask`56-method is recommended. The reason for this is that due to how the reload57-mechanism works there are some bizarre side-effects (like executing58-certain code twice, sometimes crashing without message or dying when a59-syntax or import error happens).82+.. code-block:: python83 61-It is however still a perfectly valid method for invoking a non automatic62-reloading application.84+ if __name__ == "__main__":85+ app.run(debug=True)86+87+.. code-block:: text88+89+ $ python hello.pymodified:src/flask/cli.py+1 added-1 removed
804 unmodified lines805 help="Enable or disable the debugger. By default the debugger "806 "is active if debug is enabled.",807 )808 @click.option(809- "--eager-loading/--lazy-loader",809+ "--eager-loading/--lazy-loading",810 default=None,811 help="Enable or disable eager loading. By default eager "812 "loading is enabled if the reloader is disabled.",813 )159 unmodified lines