debugging.rst
This file
Path
docs/debugging.rst
147 lines · 4.1 KiB
Last changed by
Merge pull request #4412 from otherJL0/mainDavid Lordbefore adoption981a94d
History of this fileTake it
The walk stopped after 200 commits: lines older than e071734 point at it.
Merge pull request #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
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 #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
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 #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
line 50why, one step back50Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
lines 51–55why, one step back51 .. code-block:: text5253 $ export FLASK_ENV=development54 $ flask run55Merge pull request #4412 from otherJL0/mainDavid Lordbefore adoption981a94d
lines 56–62why, one step back56 .. group-tab:: Fish5758 .. code-block:: text5960 $ set -x FLASK_ENV development61 $ flask run62Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
lines 63–76why, one step back63 .. group-tab:: CMD6465 .. code-block:: text6667 > set FLASK_ENV=development68 > flask run6970 .. group-tab:: Powershell7172 .. code-block:: text7374 > $env:FLASK_ENV = "development"75 > flask run76Merge pull request #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
lines 77–78why, one step back77``FLASK_ENV`` can only be set as an environment variable. When running78from Python code, passing ``debug=True`` enables debug mode, which isMerge pull request #4266 from kkirsche/patch-1Grey Libefore adoptionca0033c
line 79why, one step back79mostly equivalent. Debug mode can be controlled separately fromMerge pull request #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
lines 80–106why, one step back80``FLASK_ENV`` with the ``FLASK_DEBUG`` environment variable as well.8182.. code-block:: python8384 app.run(debug=True)8586:doc:`/server` and :doc:`/cli` have more information about running the87debugger, debug mode, and development mode. More information about the88debugger can be found in the `Werkzeug documentation89<https://werkzeug.palletsprojects.com/debug/>`__.909192External Debuggers93------------------9495External debuggers, such as those provided by IDEs, can offer a more96powerful debugging experience than the built-in debugger. They can also97be used to step through code during a request before an error is raised,98or if no error is raised. Some even have a remote mode so you can debug99code running on another machine.100101When using an external debugger, the app should still be in debug mode,102but it can be useful to disable the built-in debugger and reloader,103which can interfere.104105When running from the command line:106Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
line 107why, one step back107.. tabs::Merge pull request #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
line 108why, one step back108Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
lines 109–113why, one step back109 .. group-tab:: Bash110111 .. code-block:: text112113 $ export FLASK_ENV=developmentMerge pull request #4412 from otherJL0/mainDavid Lordbefore adoption981a94d
lines 114–120why, one step back114 $ flask run --no-debugger --no-reload115116 .. group-tab:: Fish117118 .. code-block:: text119120 $ set -x FLASK_ENV developmentAdd command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc
lines 121–135why, one step back121 $ flask run --no-debugger --no-reload122123 .. group-tab:: CMD124125 .. code-block:: text126127 > set FLASK_ENV=development128 > flask run --no-debugger --no-reload129130 .. group-tab:: Powershell131132 .. code-block:: text133134 > $env:FLASK_ENV = "development"135 > flask run --no-debugger --no-reloadMerge pull request #3734 from pallets/dependabot/pip/sphinx-3.2.1dependabot-preview[bot]before adoptione071734
lines 136–147why, one step back136137When running from Python:138139.. code-block:: python140141 app.run(debug=True, use_debugger=False, use_reloader=False)142143Disabling these isn't required, an external debugger will continue to144work with the following caveats. If the built-in debugger is not145disabled, it will catch unhandled exceptions before the external146debugger can. If the reloader is not disabled, it could cause an147unexpected reload if code changes during debugging.