server.rst
This file
Path
docs/server.rst
115 lines · 3.6 KiB
Last changed by
Merge pull request #4980 from pallets/release-2.2.3David Lordbefore adoption6a392af
History of this fileTake it
The walk stopped after 200 commits: lines older than 4240ace point at it.
Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 1–5why, one step back1.. currentmodule:: flask23Development Server4==================5Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 6–8why, one step back6Flask provides a ``run`` command to run the application with a development server. In7debug mode, this server provides an interactive debugger and will reload when code is8changed.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 9–20why, one step back910.. warning::1112 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.1718Command Line19------------20Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 21–23why, one step back21The ``flask run`` CLI command is the recommended way to run the development server. Use22the ``--app`` option to point to your application, and the ``--debug`` option to enable23debug mode.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 24why, one step back24Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
lines 25–26why, one step back25.. code-block:: text26Merge pull request #4980 from pallets/release-2.2.3David Lordbefore adoption6a392af
line 27why, one step back27 $ flask --app hello run --debugMerge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
line 28why, one step back28Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 29–32why, one step back29This enables debug mode, including the interactive debugger and reloader, and then30starts the server on http://localhost:5000/. Use ``flask run --help`` to see the31available options, and :doc:`/cli` for detailed instructions about configuring and using32the CLI.Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
line 33why, one step back33Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 34why, one step back34Merge branch '2.0.x'David Lordbefore adoptionedac7e3
lines 35–50why, one step back35.. _address-already-in-use:3637Address already in use38~~~~~~~~~~~~~~~~~~~~~~3940If another program is already using port 5000, you'll see an ``OSError``41when the server tries to start. It may have one of the following42messages:4344- ``OSError: [Errno 98] Address already in use``45- ``OSError: [WinError 10013] An attempt was made to access a socket46 in a way forbidden by its access permissions``4748Either identify and stop the other program, or use49``flask run --port 5001`` to pick a different port.50Merge branch '2.0.x'David Lordbefore adoption0fb5c2f
lines 51–53why, one step back51You can use ``netstat`` or ``lsof`` to identify what process id is using52a port, then use other operating system tools stop that process. The53following example shows that process id 6847 is using port 5000.Merge branch '2.0.x'David Lordbefore adoptionedac7e3
lines 54–56why, one step back5455.. tabs::56Merge branch '2.0.x'David Lordbefore adoption0fb5c2f
line 57why, one step back57 .. tab:: ``netstat`` (Linux)Merge branch '2.0.x'David Lordbefore adoptionedac7e3
lines 58–63why, one step back5859 .. code-block:: text6061 $ netstat -nlp | grep 500062 tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 6847/python63Merge branch '2.0.x'David Lordbefore adoption0fb5c2f
line 64why, one step back64 .. tab:: ``lsof`` (macOS / Linux)Merge branch '2.0.x'David Lordbefore adoptionedac7e3
lines 65–67why, one step back6566 .. code-block:: text67Merge branch '2.0.x'David Lordbefore adoption0fb5c2f
lines 68–74why, one step back68 $ lsof -P -i :500069 Python 6847 IPv4 TCP localhost:5000 (LISTEN)7071 .. tab:: ``netstat`` (Windows)7273 .. code-block:: text74Merge branch '2.0.x'David Lordbefore adoptionedac7e3
lines 75–77why, one step back75 > netstat -ano | findstr 500076 TCP 127.0.0.1:5000 0.0.0.0:0 LISTENING 684777Merge branch '2.0.x'David Lordbefore adoption0fb5c2f
line 78why, one step back78macOS Monterey and later automatically starts a service that uses portMerge branch '2.0.x'David Lordbefore adoptionedac7e3
lines 79–82why, one step back795000. To disable the service, go to System Preferences, Sharing, and80disable "AirPlay Receiver".8182Merge pull request #4718 from pallets/remove-lazy-optionDavid Lordbefore adoption633f421
lines 83–84why, one step back83Deferred Errors on Reload84~~~~~~~~~~~~~~~~~~~~~~~~~Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 85–99why, one step back8586When using the ``flask run`` command with the reloader, the server will87continue to run even if you introduce syntax errors or other88initialization errors into the code. Accessing the site will show the89interactive debugger for the error, rather than crashing the server.9091If a syntax error is already present when calling ``flask run``, it will92fail immediately and show the traceback rather than waiting until the93site is accessed. This is intended to make errors more visible initially94while still allowing the server to handle errors on reload.959697In Code98-------99Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 100–103why, one step back100The development server can also be started from Python with the :meth:`Flask.run`101method. This method takes arguments similar to the CLI options to control the server.102The main difference from the CLI command is that the server will crash if there are103errors when reloading. ``debug=True`` can be passed to enable debug mode.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 104why, one step back104Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 105–106why, one step back105Place the call in a main block, otherwise it will interfere when trying to import and106run the application with a production server later.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 107–115why, one step back107108.. code-block:: python109110 if __name__ == "__main__":111 app.run(debug=True)112113.. code-block:: text114115 $ python hello.py