My favorites | Sign in
Project Home
Search
for
RunServerPlus  
RunServerPlus-typical runserver with Werkzeug debugger baked in
Updated Feb 4, 2010 by carl.j.meyer

Introduction

This item requires that you have the Werkzeug WSGI utilities (version 0.3) installed. Included with Werkzeug is a kick ass debugger that renders nice debugging tracebacks and adds an AJAX based debugger (which allows to execute code in the context of the traceback’s frames). Additionally it provides a nice access view to the source code.

Getting Started

To get started we just use the runserver_plus command instead of the normal runserver command:

python manage.py runserver_plus

 * Running on http://127.0.0.1:8000/
 * Restarting with reloader...
Validating models...
0 errors found

Django version 0.97-newforms-admin-SVN-unknown, using settings 'screencasts.settings'
Development server is running at http://127.0.0.1:8000/
Using the Werkzeug debugger (http://werkzeug.pocoo.org/)
Quit the server with CONTROL-C.

Note: all normal runserver options apply. In other words, if you need to change the port number or the host information, you can do so like you would normally.

Using

Whenever we hit an exception in our code, instead of the normal Django traceback page appearing, we see the Werkzeug traceback page instead.

Along with the typical traceback information we have a couple of options. These options appear when you hover over a particular traceback line. Notice that two buttons appear to the right:

The options are:

View Source

This displays the source below the traceback:

Being able to view the source file is handy because you are able to get more context information around where the error occurred. The actual traceback areas are highlighted so they are easy to spot.

One awkward piece about this is that the page is not scrolled to the bottom. At first I thought nothing was happening because of this.

Interactive Debugging Console

When you click on this button a new pane will open up below the traceback line you're on. This is the money shot:

An ajax based console appears in the pane and you can begin debugging away. Notice in the screenshot above I did a print environ to see what was in the environment parameter coming into the function.

WARNING: This should never be used in any kind of production environment. Not even for a quick check into a problem. I cannot emphasize this enough. The interactive debugger allows you to evaluate python code right against the server. You've been warned.

Comment by juan...@gmail.com, Jul 29, 2009

My only comment to this is: WOW!

Comment by electron...@gmail.com, Oct 16, 2009
http://blog.michaeltrier.com/assets/2008/6/22/werkzeug-traceback.png

imgs rc are broken

Comment by breno...@gmail.com, Oct 21, 2009

should be

Comment by tsm...@gmail.com, Jun 23, 2010

I installed the latest django extension (django-extensions-0.4.1.tar.gz ) on django 1.2.1. when running server_plus ... it complained that werkzeug was missing

<snip> Error: Werkzeug is required to use runserver_plus. Please visit http://werkzeug.pocoo.org/download </snip>

As the Werkzeug site indicated, I did an easy_install as indicated herebelow : <snip> Error: Werkzeug is required to use runserver_plus. Please visit http://werkzeug.pocoo.org/download Thomas-SMETSs-MacBook?-Pro:sportotop tsmets$ easy_install Werkzeug Searching for Werkzeug Reading http://pypi.python.org/simple/Werkzeug/ Reading http://werkzeug.pocoo.org/ Reading http://trac.pocoo.org/repos/werkzeug/trunk Best match: Werkzeug 0.6.2 Downloading http://pypi.python.org/packages/source/W/Werkzeug/Werkzeug-0.6.2.tar.gz#md5=519408350346a247333bb5d584371724 Processing Werkzeug-0.6.2.tar.gz Running Werkzeug-0.6.2/setup.py -q bdist_egg --dist-dir /var/folders/aj/ajWxX+uAH+GwVYy18H9T7++++TI/-Tmp-/easy_install-f92lTl/Werkzeug-0.6.2/egg-dist-tmp-Yw2aEi? no previously-included directories found matching 'docs/build/doctrees' zip_safe flag not set; analyzing archive contents... werkzeug.init: module references file werkzeug.init: module references path werkzeug.serving: module references file werkzeug.utils: module references path werkzeug.contrib.jsrouting: module MAY be using inspect.trace werkzeug.debug.init: module references file werkzeug.debug.render: module references file werkzeug.debug.tbtools: module MAY be using inspect.getsourcefile werkzeug.debug.utils: module references file Adding Werkzeug 0.6.2 to easy-install.pth file

Installed /Library/Python/2.6/site-packages/Werkzeug-0.6.2-py2.6.egg Processing dependencies for Werkzeug Finished processing dependencies for Werkzeug </snip>

It did not help ... It keeps on requesting the installation of the Werkzeug library ...

\T,

Comment by hacke...@gmail.com, Oct 17, 2010

Why should you never use this in production? - Cant you just limit the debug info to only be shown if the request is coming from the developer's IP? (e.g. INTERNAL_IPS = (192.168.0.7,) in settings.py)


Sign in to add a comment
Powered by Google Project Hosting