How to do nested comments in Flask/Jinja?

后端 未结 2 480
粉色の甜心
粉色の甜心 2021-02-10 14:54

Like the comments in Hacker News and Reddit. I\'ve looked at Jinja\'s docs but I can\'t find anything about recursion (which I assume is how this sort of thing is done). Any ide

2条回答
  •  攒了一身酷
    2021-02-10 15:17

    Unless, you give an example how your comment data is laid out, I can only give a basic example how recursive for loops work:

    {%- for item in comments recursive %}
        
  • {{ item.text }}
  • {%- if item.children -%}
      {{ loop(item.children) }}
    {%- endif %}
  • {%- endfor %}

提交回复
热议问题