class Token

from django.template.base import Token


  

Ancestors (MRO)

  1. builtins.object
  2. django.template.base.Token
AttributeTypeDefined in
def __init__(self, token_type, contents, position=None, lineno=None)
django.template.base.Token
A token representing a string from the template.

token_type
    A TokenType, either .TEXT, .VAR, .BLOCK, or .COMMENT.

contents
    The token source string.

position
    An optional tuple containing the start and end index of the token
    in the template source. This is used for traceback information
    when debug is on.

lineno
    The line number the token appears on in the template source.
    This is used for traceback information and gettext files.
    def __init__(self, token_type, contents, position=None, lineno=None):
        """
        A token representing a string from the template.

        token_type
            A TokenType, either .TEXT, .VAR, .BLOCK, or .COMMENT.

        contents
            The token source string.

        position
            An optional tuple containing the start and end index of the token
            in the template source. This is used for traceback information
            when debug is on.

        lineno
            The line number the token appears on in the template source.
            This is used for traceback information and gettext files.
        """
        self.token_type = token_type
        self.contents = contents
        self.lineno = lineno
        self.position = position
def __repr__(self)
django.template.base.Token
Return repr(self).
    def __repr__(self):
        token_name = self.token_type.name.capitalize()
        return '<%s token: "%s...">' % (
            token_name,
            self.contents[:20].replace("\n", ""),
        )
def split_contents(self)
django.template.base.Token
    def split_contents(self):
        split = []
        bits = smart_split(self.contents)
        for bit in bits:
            # Handle translation-marked template pieces
            if bit.startswith(('_("', "_('")):
                sentinel = bit[2] + ")"
                trans_bit = [bit]
                while not bit.endswith(sentinel):
                    bit = next(bits)
                    trans_bit.append(bit)
                bit = " ".join(trans_bit)
            split.append(bit)
        return split