How to do nested comments in Flask/Jinja?

flask, jinja2, python

Solution

Use macros, they support recursion. http://jinja.pocoo.org/docs/templates/#macros

Edit: for loops also support recursion, this would work as well. http://jinja.pocoo.org/docs/templates/#for

Problem

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 ideas? Thanks in advance. EDIT: I already have the data (from an API), and the comments are objects which have children. I just need to know how to render the children recursively in Jinja.

Original source