Python 2.7 如何在jinja2、Python2.7中创建嵌套for循环而不显示双重结果

Python 2.7 如何在jinja2、Python2.7中创建嵌套for循环而不显示双重结果,python-2.7,google-app-engine,jinja2,webapp2,Python 2.7,Google App Engine,Jinja2,Webapp2,你好。 我试图列出一个用户的所有评论以及该评论所属的主题,但我在comment_list.html中得到了两个值。 我想我没有把它套好 我的Python hadler如下所示: class CommentsListHandler(BaseHandler): def get(self): user = users.get_current_user() comments = Comment.query(Comment.deleted==False, Comment.author_em

你好。 我试图列出一个用户的所有评论以及该评论所属的主题,但我在comment_list.html中得到了两个值。 我想我没有把它套好

我的Python hadler如下所示:

class CommentsListHandler(BaseHandler):
def get(self):
    user = users.get_current_user()
    comments = Comment.query(Comment.deleted==False, Comment.author_email==user.email()).fetch()
    topics = Topic.query(Topic.deleted==False).fetch()
    params = {"comments": comments, "topics": topics}
    return self.render_template("comments_list.html", params=params)
我的jinja2如下:

class CommentsListHandler(BaseHandler):
def get(self):
    user = users.get_current_user()
    comments = Comment.query(Comment.deleted==False, Comment.author_email==user.email()).fetch()
    topics = Topic.query(Topic.deleted==False).fetch()
    params = {"comments": comments, "topics": topics}
    return self.render_template("comments_list.html", params=params)
{%用于注释中的注释|排序(attribute='created')%}
{主题%中的主题为%s}
{{comment.created.strftime(“%d.%m.%Y在%H:%m”)}}上的{{comment.author_email}}}
主题:
{{comment.content}

{%endfor%}
{%endfor%}
我已经设法解决了这个问题:

{%用于注释中的注释|排序(attribute='created')%}
{主题%中的主题为%s}
{%if-topic.key.id()==comment.topic\u id%}
{{comment.created.strftime(“%d.%m.%Y在%H:%m”)}}上的{{comment.author_email}}}
主题:
{{comment.content}

{%endif%} {%endfor%}
{%endfor%}
您是否可以通过示例用户、注释和主题添加您的实际输出与您期望的HTML?