debugtools/templatetags/debugtools_tags.py
def print_variables(self, context):
        """
        Print a set of variables
        """
        text = []
        for name, expr in self.variables:
            # Some extended resolving, to handle unknown variables
            data = ''
            try:
                if isinstance(expr.var, Variable):
                    data = expr.var.resolve(context)
                else:
                    data = expr.resolve(context)  # could return TEMPLATE_STRING_IF_INVALID
            except VariableDoesNotExist as e:
                # Failed to resolve, display exception inline
                keys = []
                for scope in context:
                    keys += scope.keys()
                keys = sorted(set(keys))  # Remove duplicates, e.g. csrf_token
                return ERROR_TYPE_BLOCK.format(style=PRE_ALERT_STYLE, error=escape(u"Variable '{0}' not found!  Available context variables are:\n\n{1}".format(expr, u', '.join(keys))))
            else:
                # Regular format
                textdata = linebreaksbr(pformat_django_context_html(data))

            # At top level, prefix class name if it's a longer result
            if isinstance(data, SHORT_NAME_TYPES):
                text.append(BASIC_TYPE_BLOCK.format(style=PRE_STYLE, name=name, value=textdata))
            else:
                text.append(OBJECT_TYPE_BLOCK.format(style=PRE_STYLE, name=name, type=data.__class__.__name__, value=textdata))
        return u''.join(text)
def print_variables(self, context):
        text = []
        for name, expr in self.variables:
            # Some extended resolving, to handle unknown variables
            data = ''
            try:
                if isinstance(expr.var, Variable):
                    data = expr.var.resolve(context)
                else:
                    data = expr.resolve(context)  # could return TEMPLATE_STRING_IF_INVALID
            except VariableDoesNotExist as e:
                # Failed to resolve, display exception inline
                keys = []
                for scope in context:
                    keys += scope.keys()
                keys = sorted(set(keys))  # Remove duplicates, e.g. csrf_token
                return ERROR_TYPE_BLOCK.format(style=PRE_ALERT_STYLE, error=escape(u"Variable '{0}' not found!  Available context variables are:\n\n{1}".format(expr, u', '.join(keys))))
            else:
                # Regular format
                textdata = linebreaksbr(pformat_django_context_html(data))

            # At top level, prefix class name if it's a longer result
            if isinstance(data, SHORT_NAME_TYPES):
                text.append(BASIC_TYPE_BLOCK.format(style=PRE_STYLE, name=name, value=textdata))
            else:
                text.append(OBJECT_TYPE_BLOCK.format(style=PRE_STYLE, name=name, type=data.__class__.__name__, value=textdata))
        return u''.join(text)
def print_variables ( self , context ) : text = [ ] for name , expr in self . variables : # Some extended resolving, to handle unknown variables data = '' try : if isinstance ( expr . var , Variable ) : data = expr . var . resolve ( context ) else : data = expr . resolve ( context ) # could return TEMPLATE_STRING_IF_INVALID except VariableDoesNotExist as e : # Failed to resolve, display exception inline keys = [ ] for scope in context : keys += scope . keys ( ) keys = sorted ( set ( keys ) ) # Remove duplicates, e.g. csrf_token return ERROR_TYPE_BLOCK . format ( style = PRE_ALERT_STYLE , error = escape ( u"Variable '{0}' not found!  Available context variables are:\n\n{1}" . format ( expr , u', ' . join ( keys ) ) ) ) else : # Regular format textdata = linebreaksbr ( pformat_django_context_html ( data ) ) # At top level, prefix class name if it's a longer result if isinstance ( data , SHORT_NAME_TYPES ) : text . append ( BASIC_TYPE_BLOCK . format ( style = PRE_STYLE , name = name , value = textdata ) ) else : text . append ( OBJECT_TYPE_BLOCK . format ( style = PRE_STYLE , name = name , type = data . __class__ . __name__ , value = textdata ) ) return u'' . join ( text )
Print a set of variables
Print a set of variables