Created
April 18, 2023 08:01
-
-
Save diversen/dd8cfb21ee10b68300063252f8869cd0 to your computer and use it in GitHub Desktop.
jinja2 recusive print dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro print_primitive_values(data) %} | |
{% if data is mapping %} | |
{% for key, value in data.items() %} | |
{% if value is mapping or value is iterable %} | |
<strong>{{ key }}</strong>: {{ print_primitive_values(value) }} | |
{% else %} | |
<strong>{{ key }}</strong>: {{ value }} | |
{% endif %} | |
{% endfor %} | |
{% elif data is iterable and data is not string %} | |
{% for value in data %} | |
{{ print_primitive_values(value) }} | |
{% endfor %} | |
{% else %} | |
<p>{{ data }}</p><br> | |
{% endif %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment