class BaseContext

from django.template.context import BaseContext


  

Ancestors (MRO)

  1. builtins.object
  2. django.template.context.BaseContext
AttributeTypeDefined in
AttributeValueDefined in
def __contains__(self, key)
django.template.context.BaseContext
    def __contains__(self, key):
        return any(key in d for d in self.dicts)
def __copy__(self)
django.template.context.BaseContext
    def __copy__(self):
        duplicate = copy(super())
        duplicate.dicts = self.dicts[:]
        return duplicate
def __delitem__(self, key)
django.template.context.BaseContext
Delete a variable from the current context
    def __delitem__(self, key):
        "Delete a variable from the current context"
        del self.dicts[-1][key]
def __eq__(self, other)
django.template.context.BaseContext
Compare two contexts by comparing theirs 'dicts' attributes.
    def __eq__(self, other):
        """
        Compare two contexts by comparing theirs 'dicts' attributes.
        """
        if not isinstance(other, BaseContext):
            return NotImplemented
        # flatten dictionaries because they can be put in a different order.
        return self.flatten() == other.flatten()
def __getitem__(self, key)
django.template.context.BaseContext
Get a variable's value, starting at the current context and going upward
    def __getitem__(self, key):
        "Get a variable's value, starting at the current context and going upward"
        for d in reversed(self.dicts):
            if key in d:
                return d[key]
        raise KeyError(key)
def __init__(self, dict_=None)
django.template.context.BaseContext
Initialize self.  See help(type(self)) for accurate signature.
    def __init__(self, dict_=None):
        self._reset_dicts(dict_)
def __iter__(self)
django.template.context.BaseContext
    def __iter__(self):
        return reversed(self.dicts)
def __repr__(self)
django.template.context.BaseContext
Return repr(self).
    def __repr__(self):
        return repr(self.dicts)
def __setitem__(self, key, value)
django.template.context.BaseContext
Set a variable in the current context
    def __setitem__(self, key, value):
        "Set a variable in the current context"
        self.dicts[-1][key] = value
def flatten(self)
django.template.context.BaseContext
Return self.dicts as one dictionary.
    def flatten(self):
        """
        Return self.dicts as one dictionary.
        """
        flat = {}
        for d in self.dicts:
            flat.update(d)
        return flat
def get(self, key, otherwise=None)
django.template.context.BaseContext
    def get(self, key, otherwise=None):
        for d in reversed(self.dicts):
            if key in d:
                return d[key]
        return otherwise
def new(self, values=None)
django.template.context.BaseContext
Return a new context with the same properties, but with only the
values given in 'values' stored.
    def new(self, values=None):
        """
        Return a new context with the same properties, but with only the
        values given in 'values' stored.
        """
        new_context = copy(self)
        new_context._reset_dicts(values)
        return new_context
def pop(self)
django.template.context.BaseContext
    def pop(self):
        if len(self.dicts) == 1:
            raise ContextPopException
        return self.dicts.pop()
def push(self, *args, **kwargs)
django.template.context.BaseContext
    def push(self, *args, **kwargs):
        dicts = []
        for d in args:
            if isinstance(d, BaseContext):
                dicts += d.dicts[1:]
            else:
                dicts.append(d)
        return ContextDict(self, *dicts, **kwargs)
def set_upward(self, key, value)
django.template.context.BaseContext
Set a variable in one of the higher contexts if it exists there,
otherwise in the current context.
    def set_upward(self, key, value):
        """
        Set a variable in one of the higher contexts if it exists there,
        otherwise in the current context.
        """
        context = self.dicts[-1]
        for d in reversed(self.dicts):
            if key in d:
                context = d
                break
        context[key] = value
def setdefault(self, key, default=None)
django.template.context.BaseContext
    def setdefault(self, key, default=None):
        try:
            return self[key]
        except KeyError:
            self[key] = default
        return default