Login

Template Context Debugger with Pydev

Author:
showell
Posted:
June 17, 2009
Language:
Python
Version:
1.0
Tags:
template debug pydev
Score:
0 (after 0 ratings)

This snippet is a variation on snippet 1550 that works with the Eclipse pydev plugin.

This allows you to set up a breakpoint anywhere in your template code, by simply writing {% pydev_debug %}. Be sure to launch pydev in debugger mode first.

Once you're in the debugger, you can explore the stack and quickly find which context variables are set. This can be especially useful inside for loops, etc., where you want to see how the templating code is mucking with the context. This can also be useful when your templates are ultimately rendered by code that might not understand very well, such as generics.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.template import Library, Node
register = Library()


class PydevDebugNode(Node):
    def render(self, context):
        try:
            import pydevd #@UnresolvedImport
            pydevd.connected = True
            pydevd.settrace()
            return ''
        except:
            # It might be more clear to just let this exception pass through
            return 'Debugger was not turned on'

@register.tag
def pydev_debug(parser, token):
    return PydevDebugNode()

More like this

  1. Template context debugger with (I)Pdb by denis 5 years, 9 months ago
  2. Updated - Template context debugger with (I)Pdb by dnordberg 5 years, 6 months ago
  3. View decorator to automate templates. by jafo 5 years ago
  4. "Partial Templates" - an alternative to "include" by vigrid 6 years, 1 month ago
  5. Partial templates, combine with and include by koblas 4 years, 10 months ago

Comments

Please login first before commenting.