[Answered ]-What are the different dicts in Django Debug Toolbar's 'Toggle context' areas?

2👍

Django templates have something called scopes. Each scope is an layer of variables, available only in current scope and all child scopes.

Each of ‘layers’ that are responsible for rendering template will add it’s own scope. By default there are 3 scopes: root scope, that will have some definitions of constant variables:

{'False': False, 'None': None, 'True': True}

context_processors scope, that will contain all variables injected into your templates globally from context processors:

{'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10,
                            'ERROR': 40,
                            'INFO': 20,
                            'SUCCESS': 25,
                            'WARNING': 30},
 'csrf_token': <SimpleLazyObject: 'zJvE5t6k9KdxMfUmU4SOvRTOC2rh7Pvw'>,
 'debug': True,
 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x10877b860>,
 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x10877de10>,
 'request': '<<request>>',
 'sql_queries': <function debug.<locals>.<lambda> at 0x108d3de18>,
 'user': <SimpleLazyObject: <User: phil>>}

And Response scope, that will have all variables passed into Response object:

{'is_paginated': True,
 'object_list': '<<queryset of twitter.Tweet>>',
 'page_obj': <Page 1 of 330>,
 'paginator': <ditto.ditto.paginator.DiggPaginator object at 0x10877bac8>,
 'view': <ditto.twitter.views.TweetList object at 0x108782dd8>}

There are listed in order from oldest one (root) to youngest one, that means: all variables mentioned in dicts mentioned later will cover variables mentioned above.

Additional scopes can be created by some template tags, for example for loop, where, include… That scopes won’t be visible in django debug toolbar.

Leave a comment