debugging.rst
This file
Path
docs/debugging.rst
133 lines · 3.9 KiB
Last changed by
Merge pull request #4266 from kkirsche/patch-1Grey Libefore adoptionca0033c
History of this fileTake it
The walk stopped after 200 commits: lines older than 1a9059d point at it.
Merge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
lines 1–46why, one step back1Debugging Application Errors2============================345In Production6-------------78**Do not run the development server, or enable the built-in debugger, in9a production environment.** The debugger allows executing arbitrary10Python code from the browser. It's protected by a pin, but that should11not be relied on for security.1213Use an error logging tool, such as Sentry, as described in14:ref:`error-logging-tools`, or enable logging and notifications as15described in :doc:`/logging`.1617If you have access to the server, you could add some code to start an18external debugger if ``request.remote_addr`` matches your IP. Some IDE19debuggers also have a remote mode so breakpoints on the server can be20interacted with locally. Only enable a debugger temporarily.212223The Built-In Debugger24---------------------2526The built-in Werkzeug development server provides a debugger which shows27an interactive traceback in the browser when an unhandled error occurs28during a request. This debugger should only be used during development.2930.. image:: _static/debugger.png31 :align: center32 :class: screenshot33 :alt: screenshot of debugger in action3435.. warning::3637 The debugger allows executing arbitrary Python code from the38 browser. It is protected by a pin, but still represents a major39 security risk. Do not run the development server or debugger in a40 production environment.4142To enable the debugger, run the development server with the43``FLASK_ENV`` environment variable set to ``development``. This puts44Flask in debug mode, which changes how it handles some errors, and45enables the debugger and reloader.46Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
line 47why, one step back47.. tabs::Merge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
line 48why, one step back48Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
line 49why, one step back49 .. group-tab:: BashMerge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
line 50why, one step back50Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
lines 51–69why, one step back51 .. code-block:: text5253 $ export FLASK_ENV=development54 $ flask run5556 .. group-tab:: CMD5758 .. code-block:: text5960 > set FLASK_ENV=development61 > flask run6263 .. group-tab:: Powershell6465 .. code-block:: text6667 > $env:FLASK_ENV = "development"68 > flask run69Merge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
lines 70–71why, one step back70``FLASK_ENV`` can only be set as an environment variable. When running71from Python code, passing ``debug=True`` enables debug mode, which isMerge pull request #4266 from kkirsche/patch-1Grey Libefore adoptionca0033c
line 72why, one step back72mostly equivalent. Debug mode can be controlled separately fromMerge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
lines 73–99why, one step back73``FLASK_ENV`` with the ``FLASK_DEBUG`` environment variable as well.7475.. code-block:: python7677 app.run(debug=True)7879:doc:`/server` and :doc:`/cli` have more information about running the80debugger, debug mode, and development mode. More information about the81debugger can be found in the `Werkzeug documentation82<https://werkzeug.palletsprojects.com/debug/>`__.838485External Debuggers86------------------8788External debuggers, such as those provided by IDEs, can offer a more89powerful debugging experience than the built-in debugger. They can also90be used to step through code during a request before an error is raised,91or if no error is raised. Some even have a remote mode so you can debug92code running on another machine.9394When using an external debugger, the app should still be in debug mode,95but it can be useful to disable the built-in debugger and reloader,96which can interfere.9798When running from the command line:99Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
line 100why, one step back100.. tabs::Merge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
line 101why, one step back101Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
lines 102–121why, one step back102 .. group-tab:: Bash103104 .. code-block:: text105106 $ export FLASK_ENV=development107 $ flask run --no-debugger --no-reload108109 .. group-tab:: CMD110111 .. code-block:: text112113 > set FLASK_ENV=development114 > flask run --no-debugger --no-reload115116 .. group-tab:: Powershell117118 .. code-block:: text119120 > $env:FLASK_ENV = "development"121 > flask run --no-debugger --no-reloadMerge pull request #3725 from pallets/dependabot/pip/sphinx-3.2.0dependabot-preview[bot]before adoption1a9059d
lines 122–133why, one step back122123When running from Python:124125.. code-block:: python126127 app.run(debug=True, use_debugger=False, use_reloader=False)128129Disabling these isn't required, an external debugger will continue to130work with the following caveats. If the built-in debugger is not131disabled, it will catch unhandled exceptions before the external132debugger can. If the reloader is not disabled, it could cause an133unexpected reload if code changes during debugging.