如何在Flask / Jinja中进行嵌套评论? [英] How to do nested comments in Flask/Jinja?

查看:227
本文介绍了如何在Flask / Jinja中进行嵌套评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像黑客新闻和Reddit中的评论一样。我看过Jinja的文档,但是找不到任何关于递归的东西(我想这是怎么做的)。任何想法?

预先感谢。

编辑:

我已经有了(来自API的)数据,并且注释是有孩子的对象。我只需要知道如何在Jinja递归呈现孩子。

解决方案

使用宏,它们支持递归。 http://jinja.pocoo.org/docs/templates/#macros http://jinja.pocoo.org/docs/templates/#for


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.

解决方案

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

这篇关于如何在Flask / Jinja中进行嵌套评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆