Updated - Template context debugger with (I)Pdb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from django.template import Library, Node

register = Library()

try:
    import ipdb as pdb
except ImportError:   
    import pdb

class PdbNode(Node):
    def render(self, context):
        # Access vars at the prompt for an easy reference to
        # variables in the context
        vars = []
        for dict in context.dicts:
            for k, v in dict.items():
                vars.append(k)
                locals()[k] = v
        pdb.set_trace()
        return ''

@register.tag("pdbdebug")
def pdbdebug_tag(parser, token):
    """Tag that inspects template context.

    Usage: 
    {% pdb_debug %}

    You can then access your context variables directly at the prompt.

    The vars variable additonally has a reference list of keys
    in the context.
    """
    return PdbNode()

@register.filter("pdbdebug")
def pdbdebug_filter(value, arg=None):
    """Filter that inspects a specific
    variable in context.

    Usage:
    {{ variable|pdbdebug }}
    """
    pdb.set_trace();  
    return ''

More like this

  1. Template context debugger with (I)Pdb by denis 3 years, 11 months ago
  2. More flexible "Partial Template" by robertrv 4 years, 3 months ago
  3. Template Context Debugger with Pydev by showell 3 years, 11 months ago
  4. Manipulate URL query strings using context variables using a template tag by JHsaunders 2 years, 7 months ago
  5. Templatetag to manage GET arguments in template by DimmuR 2 years, 6 months ago

Comments

(Forgotten your password?)