Skip to main content

parse_bits

Parse bits for template tag helpers simple_tag and inclusion_tag, in particular by detecting syntax errors and by extracting positional and keyword arguments.

def parse_bits(
parser: django.template.base.Parser,
bits: list of str,
params: list of str,
varargs: str or null,
varkw: str or null,
defaults: tuple or null,
kwonly: list of str,
kwonly_defaults: dict or null,
name: str
) - > tuple

Parse bits for template tag helpers simple_tag and inclusion_tag, in particular by detecting syntax errors and by extracting positional and keyword arguments.

Parameters

NameTypeDescription
parserdjango.template.base.ParserThe template parser instance used to compile filter expressions from the bits.
bitslist of strThe raw token segments extracted from the template tag to be parsed into arguments.
paramslist of strThe list of expected positional parameter names defined in the helper function's signature.
varargsstr or nullThe name of the variable positional arguments parameter (e.g., *args), or null if not supported.
varkwstr or nullThe name of the variable keyword arguments parameter (e.g., **kwargs), or null if not supported.
defaultstuple or nullA tuple of default values for positional parameters to determine which arguments are optional.
kwonlylist of strThe list of parameter names that must be provided as keyword-only arguments.
kwonly_defaultsdict or nullA mapping of keyword-only parameter names to their default values.
namestrThe name of the template tag being parsed, used for generating descriptive syntax error messages.

Returns

TypeDescription
tupleA two-element tuple containing a list of compiled positional argument filters and a dictionary of keyword argument filters.