# Debugging Applications
Depending on the WSGI gateway/server, exceptions are handled differently.But most of the time, exceptions go to stderr or the error log.
Since this is not the best debugging environment, Werkzeug provides aWSGI middleware that renders nice debugging tracebacks, optionally with anAJAX based debugger (which allows to execute code in the context of thetraceback's frames).
The interactive debugger however does not work in forking environmentswhich makes it nearly impossible to use on production servers. Also thedebugger allows the execution of arbitrary code which makes it a majorsecurity risk and **must never be used on production machines** because ofthat.
### Enabling the Debugger
You can enable the debugger by wrapping the application in a[DebuggedApplication](# "werkzeug.debug.DebuggedApplication") middleware. Additionally there areparameters to the run_simple() function to enable it because thisis a common task during development.
*class *werkzeug.debug.DebuggedApplication(*app*, *evalex=False*, *request_key='werkzeug.request'*, *console_path='/console'*, *console_init_func=None*, *show_hidden_frames=False*, *lodgeit_url=None*)
Enables debugging support for a given application:
~~~
from werkzeug.debug import DebuggedApplication
from myapp import app
app = DebuggedApplication(app, evalex=True)
~~~
The evalex keyword argument allows evaluating expressions in atraceback's frame context.
0.9 新版功能: The lodgeit_url parameter was deprecated.
<table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple"><li><strong>app</strong> – the WSGI application to run debugged.</li><li><strong>evalex</strong> – enable exception evaluation feature (interactivedebugging). This requires a non-forking server.</li><li><strong>request_key</strong> – The key that points to the request object in thsenvironment. This parameter is ignored in currentversions.</li><li><strong>console_path</strong> – the URL for a general purpose console.</li><li><strong>console_init_func</strong> – the function that is executed before startingthe general purpose console. The return valueis used as initial namespace.</li><li><strong>show_hidden_frames</strong> – by default hidden traceback frames are skipped.You can show them by setting this parameterto <cite>True</cite>.</li></ul></td></tr></tbody></table>
### Using the Debugger
Once enabled and an error happens during a request you will see a detailedtraceback instead of a general “internal server error”. If you have theevalex feature enabled you can also get a traceback for every frame inthe traceback by clicking on the console icon.
Once clicked a console opens where you can execute Python code in:
![a screenshot of the interactive debugger](https://box.kancloud.cn/2015-10-16_56206f28d8dd1.png)
Inside the interactive consoles you can execute any kind of Python code.Unlike regular Python consoles the output of the object reprs is coloredand stripped to a reasonable size by default. If the output is longerthan what the console decides to display a small plus sign is added tothe repr and a click will expand the repr.
To display all variables that are defined in the current frame you canuse the dump() function. You can call it without arguments to get adetailed list of all variables and their values, or with an object asargument to get a detailed list of all the attributes it has.
### Pasting Errors
If you click on the Traceback title the traceback switches over to a textbased one. The text based one can be pasted to [paste.pocoo.org](http://paste.pocoo.org/) [http://paste.pocoo.org/] with oneclick.
- 开始
- Werkzeug 文档概览
- 安装
- 过渡到 Werkzeug 1.0
- Werkzeug 教程
- API 标准
- 快速开始
- Python 3 Notes
- 服务和测试
- Debugging Applications
- 在服务器运行 WSGI 应用
- 单元测试
- 参考
- Request / Response Objects
- URL Routing
- WSGI Helpers
- HTTP Utilities
- Data Structures
- Utilities
- Context Locals
- Middlewares
- HTTP Exceptions
- 部署
- CGI
- mod_wsgi (Apache)
- FastCGI
- HTTP Proxying
- 贡献模块
- Atom Syndication
- Sessions
- Secure Cookie
- Cache
- Extra Wrappers
- Iter IO
- Fixers
- WSGI Application Profiler
- Lint Validation Middleware
- 额外说明
- Werkzeug Changelog
- Important Terms
- Unicode
- Dealing with Request Data