debugging.rst
This file
Path
docs/debugging.rst
99 lines · 3.4 KiB
Last changed by
Merge pull request #5066 from pallets/docs-passthroughDavid Lordbefore adoptiona1d0eda
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–41why, 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.41Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
line 42why, one step back42The debugger is enabled by default when the development server is run in debug mode.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 43why, one step back43Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
line 44why, one step back44.. code-block:: textMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 45why, one step back45Merge pull request #4980 from pallets/release-2.2.3David Lordbefore adoption6a392af
line 46why, one step back46 $ flask --app hello run --debugMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 47why, one step back47Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 48–49why, one step back48When running from Python code, passing ``debug=True`` enables debug mode, which is49mostly equivalent.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 50–54why, one step back5051.. code-block:: python5253 app.run(debug=True)54Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d
lines 55–57why, one step back55:doc:`/server` and :doc:`/cli` have more information about running the debugger and56debug mode. More information about the debugger can be found in the `Werkzeug57documentation <https://werkzeug.palletsprojects.com/debug/>`__.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 58–68why, one step back585960External Debuggers61------------------6263External debuggers, such as those provided by IDEs, can offer a more64powerful debugging experience than the built-in debugger. They can also65be used to step through code during a request before an error is raised,66or if no error is raised. Some even have a remote mode so you can debug67code running on another machine.68Merge pull request #5066 from pallets/docs-passthroughDavid Lordbefore adoptiona1d0eda
lines 69–71why, one step back69When using an external debugger, the app should still be in debug mode, otherwise Flask70turns unhandled errors into generic 500 error pages. However, the built-in debugger and71reloader should be disabled so they don't interfere with the external debugger.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 72why, one step back72Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
line 73why, one step back73.. code-block:: textMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 74why, one step back74Merge pull request #4980 from pallets/release-2.2.3David Lordbefore adoption6a392af
line 75why, one step back75 $ flask --app hello run --debug --no-debugger --no-reloadMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 76–82why, one step back7677When running from Python:7879.. code-block:: python8081 app.run(debug=True, use_debugger=False, use_reloader=False)82Merge pull request #5066 from pallets/docs-passthroughDavid Lordbefore adoptiona1d0eda
lines 83–99why, one step back83Disabling these isn't required, an external debugger will continue to work with the84following caveats.8586- If the built-in debugger is not disabled, it will catch unhandled exceptions before87 the external debugger can.88- If the reloader is not disabled, it could cause an unexpected reload if code changes89 during a breakpoint.90- The development server will still catch unhandled exceptions if the built-in91 debugger is disabled, otherwise it would crash on any error. If you want that (and92 usually you don't) pass ``passthrough_errors=True`` to ``app.run``.9394 .. code-block:: python9596 app.run(97 debug=True, passthrough_errors=True,98 use_debugger=False, use_reloader=False99 )