How are extra args & kwargs handled for a Jinja2 macro? The documentation isn't exactly clear offhand.
For example, this is clearly wrong:
{% macro example_1(one, two, **kwargs) %}
do macro stuff
{% endmacro %}
which results in
jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError: expected token 'name', got '**'
The documentation says:
kwargs
Like varargs but for keyword arguments. All unconsumed keyword arguments are stored in this special variable.
Unfortunately, any combo of extra keyword arguments is an error,
{% macro example_2(one, two) %}
do macro stuff
{% endmacro %}
{{ example_2(one, two, test='test') }}
TypeError: macro 'example_2' takes no keyword keyword argument 'test'
I have no examples and am not poking about in the Jinja2 source code atm. The documentation isn't clear to me at this point. Any thoughts appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…