【问题标题】:Can we use Expressions delimiters "{{ }}" within Statement delimiter "{% %}"我们可以在语句分隔符“{% %}”中使用表达式分隔符“{{ }}”吗
【发布时间】:2019-05-22 06:30:04
【问题描述】:

我想使用“jinja2”来使用“Flask”为我的博客网站显示 cmets 和回复功能,所以我试图在 cmets 部分显示回复,如示例所示,或者请建议是否有人有更好的方法来管理 cmets 和它用烧瓶回复: 这就是我的意思,如果评论有回复,那么如果在两个表中都找到评论 ID,那么它将检查表评论表和回复表,如果语句打印回复数据 {%if {{ cmets[0] }} ==回复[0]%}
cmets[0] 是comment-id(主键) & reply[0] 是回复表comment-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%}

【问题讨论】:

  • 有什么问题!!
  • 它没有给出错误,但我没有得到正确的输出......你有更好的方法来管理它???

标签: python flask jinja2


【解决方案1】:

我找到了答案,如果我想在语句分隔符中使用 jinja2 var,我不需要使用表达式分隔符: {%if cmets[0] ==reply[0]%}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多