diff --git a/src/DjangoBlog-master/templates/comments/tags/comment_item_tree.html b/src/DjangoBlog-master/templates/comments/tags/comment_item_tree.html index a9decd1..af4fd54 100644 --- a/src/DjangoBlog-master/templates/comments/tags/comment_item_tree.html +++ b/src/DjangoBlog-master/templates/comments/tags/comment_item_tree.html @@ -1,53 +1,69 @@ -{% load blog_tags %} +{% load blog_tags %} {# 加载自定义博客标签 #} + +{# 评论项模板 - 支持嵌套回复的树形结构 #}
  • + style="margin-left: {% widthratio depth 1 3 %}rem"> {# 根据深度设置左边距,实现缩进 #}
    + + {# 评论作者信息 #} + {# 评论元信息 #} + + {# 回复对象信息 #}

    - {% if comment_item.parent_comment %} -

    回复 @{{ comment_item.parent_comment.author.username }} + {% if comment_item.parent_comment %} {# 如果是回复评论 #} +
    + 回复 {# 跳转到父评论 #} + @{{ comment_item.parent_comment.author.username }} {# 显示被回复者用户名 #} +
    {% endif %}

    -

    {{ comment_item.body|escape|comment_markdown }}

    + {# 评论内容 #} +

    {{ comment_item.body|escape|comment_markdown }}

    {# 安全渲染评论内容 #} - + {# 回复按钮 #} +
    + 回复 +
    -
  • -{% query article_comments parent_comment=comment_item as cc_comments %} -{% for cc in cc_comments %} + +{# 递归加载子评论 - 构建评论树 #} +{% query article_comments parent_comment=comment_item as cc_comments %} {# 查询当前评论的子评论 #} +{% for cc in cc_comments %} {# 遍历所有子评论 #} {% with comment_item=cc template_name="comments/tags/comment_item_tree.html" %} - {% if depth >= 1 %} - {% include template_name %} - {% else %} - {% with depth=depth|add:1 %} - {% include template_name %} + {% if depth >= 1 %} {# 如果已经有一定深度 #} + {% include template_name %} {# 直接包含模板,保持当前深度 #} + {% else %} {# 如果是第一层深度 #} + {% with depth=depth|add:1 %} {# 深度加1 #} + {% include template_name %} {# 包含模板,深度递增 #} {% endwith %} {% endif %} {% endwith %}