raise an exception in jinja if we passed in a variable that is not present in the template

Viewed 12578

Is there a method for jinja2 to raise an exception when we pass a variable that is not present in the template?

PS: This is different(or opposite) from raising an exception when a variable is present in the template but it is not passed. For this I use "undefined=StrictUndefined"

3 Answers

You can also do that:

from jinja2 import Template, StrictUndefined
Template('name: {{ name }} , city: {{ city }}',undefined=StrictUndefined).render(**{"name":"foo","city":"bar"})
Related