Using Werzeug's Debugger With AppEngine
This page describes a monkeypatch to use Werkzeug's debugger in AppEngine's development server.
1. Werkzeug's Mini Templates don't work with AppEngine, so we use Jinja2. The converted templates are attached in the end of this page. Add the 'debug' dir to your project and override 'werkzeug.debug.utils', which is responsible for rendering the debugger, with our templates module:
import sys import debug.utils sys.modules['werkzeug.debug.utils'] = debug.utils
2. Also, we need to override a function used in werkzeug.debug.tbtools:
import inspect inspect.getsourcefile = inspect.getfile
Some information: inspect.getsourcefile() uses the imp module, which falls in the category "can be imported, but is empty" in AppEngine (see here).
Ta-da! That's all. Now Werkzeug's pretty debugger works with AppEngine.
Full monkeypatch
Here's the full monkeypatch for steps 1 and 2 above. To avoid running the debugger in production, it checks if it is using the development server:
app = ... build your wsgi app ...
# Only run the debugger in development.
import os, sys
if 'SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev'):
# use our debug.utils with Jinja2 templates
import debug.utils
sys.modules['werkzeug.debug.utils'] = debug.utils
# don't use inspect.getsourcefile because the imp module is empty
import inspect
inspect.getsourcefile = inspect.getfile
# wrap the application
from werkzeug import DebuggedApplication
app = DebuggedApplication(app, evalex=True)
Issues
- Pasting to lodgeit still doesn't work - probably urllib issues.
- I haven't tried to make the interactive console work. Maybe it is easy from this, maybe not.
Attachments
-
debug_jinja_templates.tgz
(3.2 kB) - added by moraes
16 months ago.
Jinja2 templates