Skip to content
Myr

debugging.rst

This file

Path

docs/debugging.rst

87 lines · 2.9 KiB

Last changed by

Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d

History of this file

Take it

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

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 1–41why, one step back
1Debugging Application Errors
2============================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.41

Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d

line 42why, one step back
42The debugger is enabled by default when the development server is run in debug mode.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 43why, one step back
43

Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727

line 44why, one step back
44.. code-block:: text

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 45why, one step back
45

Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d

line 46why, one step back
46 $ flask --app hello --debug run

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 47why, one step back
47

Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d

lines 48–49why, one step back
48When running from Python code, passing ``debug=True`` enables debug mode, which is
49mostly equivalent.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 50–54why, one step back
50
51.. code-block:: python5253 app.run(debug=True)54

Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d

lines 55–57why, one step back
55:doc:`/server` and :doc:`/cli` have more information about running the debugger and
56debug mode. More information about the debugger can be found in the `Werkzeug57documentation <https://werkzeug.palletsprojects.com/debug/>`__.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 58–72why, one step back
58
5960External 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.6869When using an external debugger, the app should still be in debug mode,70but it can be useful to disable the built-in debugger and reloader,71which can interfere.72

Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727

line 73why, one step back
73.. code-block:: text

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 74why, one step back
74

Merge pull request #4720 from pallets/deprecate-envDavid Lordbefore adoption98ca00d

line 75why, one step back
75 $ flask --app hello --debug run --no-debugger --no-reload

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 76–87why, one step back
76
77When running from Python:7879.. code-block:: python8081 app.run(debug=True, use_debugger=False, use_reloader=False)8283Disabling these isn't required, an external debugger will continue to84work with the following caveats. If the built-in debugger is not85disabled, it will catch unhandled exceptions before the external86debugger can. If the reloader is not disabled, it could cause an87unexpected reload if code changes during debugging.