Does anyone know of an existing library for inspecting elements in the template?
Currently I usually end up doing this in the view:
show_me = dir(the_deets_on_this_object)
raise ValueError()
Then I can inspect the value of show_me in the debugger stack trace.
However, this is really ugly. I’d love to be able to do this inspection in the template, like is done in php with the print_r
{% load development_show_me %}
{{the_deets_on_this_object|show_them_to_me}}
I know that this doesn’t exist in the django standard template library, but I’m hoping someone has already written this template filter so I can just happily use it.
Bonus behaviors:
- Checks for settings.DEBUG and raises an error that isn’t trapped if it is false
- wraps the output in < pre >
I’ll write it if I have to, but hopefully someone else has already done this.
In django there is much better than
print_r:if the template crashes, you have access to all variable in the debig template. you can force this by settings {% url fjkdslmjfdklmfjlsmqk %}
It’s like a super print_r on all variables.
you can install django(extensions and werkzeug, this way you can replace runserver with runserver_plus and get the same page as the one we talked about, but with interactive Python shell embeded at every line of the stack trace
you can install django_template_repl, which will let you start the debugger at anyplace in the template, in the form of a python shell or a template shell.
you can install the django-debug-toolbar to get print_r style display and much more in a JS side bar invisible to anybody but you.