我们可以在语句分隔符中使用表达式分隔符"{{ }}" "{% %}"



我想使用" jinja2"来显示我的博客网站的评论和回复功能,因此我试图在示例中显示在评论部分中显示回复部分,或者请建议如果任何人都有更好的方法来管理评论及其用烧瓶的答复:这是我的意思是,如果评论有答复,则在表"表"评论表中进行检查。回复表如果在两个表中找到注释ID如果语句打印回复数据{%如果{{注释[0]}} ==回复[0]%}
评论[0]是注释-ID(主键(&回复[0]是回复表评论-ID(外键(

{% for comments in comment_data %} #comments came from different table
<p>User:{{comments[1]}}  </p> #for user email or name
<p>comment: {{comments[2]}}</p> #for comment content
{% for reply in reply_data %} 
    {%if {{comments[0]}} ==reply[0]%} # check comments id from both table
    # i need this portion because every comment can have separate reply 
    section and reply content  
    <p>User:{{reply[1]}}  </p> #for user email or name
    <p>comment: {{reply[2]}}</p> #for reply content
    {% endif %}
{% endfor %}

{%endfor%}

我找到了答案,如果我想在语句定界符中使用jinja2 var,我不需要使用表达式定界符:{%如果注释[0] ==回复[0]%}

最新更新