Skip to content
Myr

server.rst

This file

Path

docs/server.rst

89 lines · 3.0 KiB

Last changed by

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

History of this file

Take it

The walk stopped after 200 commits: lines older than 54869a0 point at it.

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

line 1why, one step back
1.. currentmodule:: flask

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

lines 2–5why, one step back
2
3Development Server4==================5

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 6–8why, one step back
6Flask provides a ``run`` command to run the application with a
7development server. In development mode, this server provides an8interactive debugger and will reload when code is changed.

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 9why, one step back
9

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

line 10why, one step back
10.. warning::

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 11why, one step back
11

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 12–17why, one step back
12 Do not use the development server when deploying to production. It
13 is intended for use only during local development. It is not14 designed to be particularly efficient, stable, or secure.1516 See :doc:`/deploying/index` for deployment options.17

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

lines 18–20why, one step back
18Command Line
19------------20

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 21–24why, one step back
21The ``flask run`` command line script is the recommended way to run the
22development server. It requires setting the ``FLASK_APP`` environment23variable to point to your application, and ``FLASK_ENV=development`` to24fully enable development mode.

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 25why, one step back
25

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 26–28why, one step back
26.. code-block:: text
2728 $ export FLASK_APP=hello

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

lines 29–33why, one step back
29 $ export FLASK_ENV=development
30 $ flask run3132This enables the development environment, including the interactive33debugger and reloader, and then starts the server on

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 34–36why, one step back
34http://localhost:5000/. Use ``flask run --help`` to see the available
35options, and :doc:`/cli` for detailed instructions about configuring36and using the CLI.

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

lines 37–39why, one step back
37
38.. note::39

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 40–41why, one step back
40 Prior to Flask 1.0 the ``FLASK_ENV`` environment variable was not
41 supported and you needed to enable debug mode by exporting

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

lines 42–45why, one step back
42 ``FLASK_DEBUG=1``. This can still be used to control debug mode, but
43 you should prefer setting the development environment as shown44 above.45

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 46–65why, one step back
46
47Lazy or Eager Loading48~~~~~~~~~~~~~~~~~~~~~4950When using the ``flask run`` command with the reloader, the server will51continue to run even if you introduce syntax errors or other52initialization errors into the code. Accessing the site will show the53interactive debugger for the error, rather than crashing the server.54This feature is called "lazy loading".5556If a syntax error is already present when calling ``flask run``, it will57fail immediately and show the traceback rather than waiting until the58site is accessed. This is intended to make errors more visible initially59while still allowing the server to handle errors on reload.6061To override this behavior and always fail immediately, even on reload,62pass the ``--eager-loading`` option. To always keep the server running,63even on the initial call, pass ``--lazy-loading``.6465

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

lines 66–68why, one step back
66In Code
67-------68

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 69–73why, one step back
69As an alternative to the ``flask run`` command, the development server
70can also be started from Python with the :meth:`Flask.run` method. This71method takes arguments similar to the CLI options to control the server.72The main difference from the CLI command is that the server will crash73if there are errors when reloading.

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 74why, one step back
74

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 75–77why, one step back
75``debug=True`` can be passed to enable the debugger and reloader, but
76the ``FLASK_ENV=development`` environment variable is still required to77fully enable development mode.

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 78why, one step back
78

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 79–80why, one step back
79Place the call in a main block, otherwise it will interfere when trying
80to import and run the application with a production server later.

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 81why, one step back
81

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

line 82why, one step back
82.. code-block:: python

Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0

line 83why, one step back
83

Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace

lines 84–89why, one step back
84 if __name__ == "__main__":
85 app.run(debug=True)8687.. code-block:: text8889 $ python hello.py