Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Get list of all variables from Jinja template
+2
−0
Suppose you have a jinja template like this:
I am going to {{ foo }} to get some {{ bar }}. I hope I can find:
{% for i in baz %}
- {{i}}
{% endfor %}
This template will require you to pass variables foo
, bar
and baz
when rendering it. If any are missing, it will return some error about the missing variable.
Is it possible to take the template, and get a list of all the required variable names? In the example, I would need to return ['foo', 'bar', 'baz']
.
0 comment threads