1

I love Django Debug Toolbar and I mainly use it just to see the variables passed to the template (shown under the "Templates" tab on the right menu).

But the variables are shown like this

{'form': <django.forms.models.OrderForm object at 0x1033937d0>}
{'csrf_token': <django.utils.functional.__proxy__ object at 0x103394cd0>}
{'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x103393510>,
 'user': <django.utils.functional.SimpleLazyObject object at 0x10339b690>}
{'debug': True, 'sql_queries': '<<sql_queries>>'}
{'LANGUAGES': '<<languages>>',
 'LANGUAGE_BIDI': False,
 'LANGUAGE_CODE': 'en-us'}
{'MEDIA_URL': ''}
{'STATIC_URL': '/static/'}
{'TIME_ZONE': 'EDT'}
{'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x10339bb90>}
{'request': '<<request>>'}

For variables like form, messages, and request, this list isn't very informative. Is there a way to dig deeper and view all the possible attributes for these kinds of variables? Kind of like playing with the API using python manage.py shell for templates?

hobbes3
  • 28,078
  • 24
  • 87
  • 116

2 Answers2

2

You can do this more efficiently using Django-Debug-Template: https://github.com/t0ster/django-debug-template

Just load template debugger by {% load debug %} first.

Then drop a shell from templates for a particular variable by {{ var|ipdb }}

sharjeel
  • 5,825
  • 7
  • 34
  • 49
1

You can't do this with django-debug-toolbar but if you install django-extensions you can use the runserver_plus command. This replaces the default exception/debug screen with werkzug debugger which gives you access to an interactive shell.

Check out a tutorial here

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • Hmm I actually already have `runserver_plus`, how would I trigger an exception. Normally I would drop an `assert False`, but most of my views are generic, so it doesn't go through `views.py`. Is there any way to trigger the exception screen from the template? – hobbes3 Mar 28 '12 at 18:14