Is there a generic, recursive flask template?

As a way to rapidly prototype an html ui, I am looking for a generic jinja2 template, that will display an object's or dictionary name/value pairs recursively, including drilling into sub objects recursively.

So say I had this dictionary:

a_dict = {'name1': 'value1', 'name2': 'value2'}
a_dict['other'] = {'name3': 'value3', 'name4': 'value4'}

It would display something like this:

name1: value1
name2: value2
    name3: value3
    name4: value4

1 answer

  • answered 2020-02-17 03:01 DontBe3Greedy

    {% macro show_node(node) %}
       {% for key, value in node.__dict__.items() %}
            <span>{{key}}: </span>
            {% if value is mapping %} <-- not sure what to do here
                {{ show_node(value) }}
                <span>Value: {{value}}</span>
            {% endif %}
       {% endfor %}
    {% endmacro %}

    there you go