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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.