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 fileTake 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 back1.. currentmodule:: flaskMerge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
lines 2–5why, one step back23Development Server4==================5Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 6–8why, one step back6Flask provides a ``run`` command to run the application with a7development 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 back9Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
line 10why, one step back10.. warning::Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
line 11why, one step back11Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 12–17why, one step back12 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.1516 See :doc:`/deploying/index` for deployment options.17Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
lines 18–20why, one step back18Command Line19------------20Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 21–24why, one step back21The ``flask run`` command line script is the recommended way to run the22development 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 back25Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 26–28why, one step back26.. code-block:: text2728 $ export FLASK_APP=helloMerge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
lines 29–33why, one step back29 $ export FLASK_ENV=development30 $ flask run3132This enables the development environment, including the interactive33debugger and reloader, and then starts the server onMerge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 34–36why, one step back34http://localhost:5000/. Use ``flask run --help`` to see the available35options, 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 back3738.. note::39Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 40–41why, one step back40 Prior to Flask 1.0 the ``FLASK_ENV`` environment variable was not41 supported and you needed to enable debug mode by exportingMerge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
lines 42–45why, one step back42 ``FLASK_DEBUG=1``. This can still be used to control debug mode, but43 you should prefer setting the development environment as shown44 above.45Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 46–65why, one step back4647Lazy 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``.6465Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
lines 66–68why, one step back66In Code67-------68Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 69–73why, one step back69As an alternative to the ``flask run`` command, the development server70can 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 back74Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 75–77why, one step back75``debug=True`` can be passed to enable the debugger and reloader, but76the ``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 back78Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 79–80why, one step back79Place the call in a main block, otherwise it will interfere when trying80to import and run the application with a production server later.Merge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
line 81why, one step back81Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
line 82why, one step back82.. code-block:: pythonMerge pull request #2793 from tiagocoutinho/patch-1Hsiaoming Yangbefore adoption54869a0
line 83why, one step back83Merge pull request #3434 from pallets/eager-loadDavid Lordbefore adoptionbfa9ace
lines 84–89why, one step back84 if __name__ == "__main__":85 app.run(debug=True)8687.. code-block:: text8889 $ python hello.py