From 873d825a80eecd172399ff0ea82122ee13efc960 Mon Sep 17 00:00:00 2001 From: pa2g3nmk9 <3474779149@qq.com> Date: Sun, 19 Oct 2025 16:44:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'src/DjangoBlog-master/tem?= =?UTF-8?q?plates/comments/tags/comment=5Fitem=5Ftree.html'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comments/tags/comment_item_tree.html | 66 ++++++++++++------- 1 file changed, 41 insertions(+), 25 deletions(-) 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 %}