Skip to content
Myr

server.rst

This file

Path

docs/server.rst

109 lines · 3.4 KiB

Last changed by

Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc

History of this file

Take it

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

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

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

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

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 #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

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 #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

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 #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

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 #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 25why, one step back
25

Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc

line 26why, one step back
26.. tabs::

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

line 27why, one step back
27

Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc

lines 28–50why, one step back
28 .. group-tab:: Bash
2930 .. code-block:: text3132 $ export FLASK_APP=hello33 $ export FLASK_ENV=development34 $ flask run3536 .. group-tab:: CMD3738 .. code-block:: text3940 > set FLASK_APP=hello41 > set FLASK_ENV=development42 > flask run4344 .. group-tab:: Powershell4546 .. code-block:: text4748 > $env:FLASK_APP = "hello"49 > $env:FLASK_ENV = "development"50 > flask run

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 51–53why, one step back
51
52This enables the development environment, including the interactive53debugger and reloader, and then starts the server on

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

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

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 57–59why, one step back
57
58.. note::59

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

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

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 62–65why, one step back
62 ``FLASK_DEBUG=1``. This can still be used to control debug mode, but
63 you should prefer setting the development environment as shown64 above.65

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

lines 66–85why, one step back
66
67Lazy or Eager Loading68~~~~~~~~~~~~~~~~~~~~~6970When using the ``flask run`` command with the reloader, the server will71continue to run even if you introduce syntax errors or other72initialization errors into the code. Accessing the site will show the73interactive debugger for the error, rather than crashing the server.74This feature is called "lazy loading".7576If a syntax error is already present when calling ``flask run``, it will77fail immediately and show the traceback rather than waiting until the78site is accessed. This is intended to make errors more visible initially79while still allowing the server to handle errors on reload.8081To override this behavior and always fail immediately, even on reload,82pass the ``--eager-loading`` option. To always keep the server running,83even on the initial call, pass ``--lazy-loading``.8485

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 86–88why, one step back
86In Code
87-------88

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

lines 89–93why, one step back
89As an alternative to the ``flask run`` command, the development server
90can also be started from Python with the :meth:`Flask.run` method. This91method takes arguments similar to the CLI options to control the server.92The main difference from the CLI command is that the server will crash93if there are errors when reloading.

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 94why, one step back
94

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

lines 95–97why, one step back
95``debug=True`` can be passed to enable the debugger and reloader, but
96the ``FLASK_ENV=development`` environment variable is still required to97fully enable development mode.

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 98why, one step back
98

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

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

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 101why, one step back
101

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

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

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 103why, one step back
103

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

lines 104–109why, one step back
104 if __name__ == "__main__":
105 app.run(debug=True)106107.. code-block:: text108109 $ python hello.py