Le 21/02/2012 12:08, Cosmia Luna a écrit :
Given a template t:
t=Template('{{ foo }}{{ bar }}')
t.render(foo=1) # an UndefinedVariableError('variable bar is undefined')
should be raised here
t.render(foo=1, bar=2) # normal output: '12'
t.render(foo=1, bar=2, foobar=3) # a TooManyVariablesError('there is no
variable named boobar') should be raised here.
When my template get larger, I sometime pass more or less argument than
needed.
Is it possible to raise an exception like this?
Hi,
You can use StrictUndefined so that undefined variables raise an
exception when used instead of just giving the empty string:
http://jinja.pocoo.org/docs/api/#jinja2.StrictUndefined
As to detecting passed but unused variables, maybe the meta API can help:
http://jinja.pocoo.org/docs/api/#jinja2.meta.find_undeclared_variables
Regards,
--
Simon Sapin
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.