Skip to content

feat: 添加评论删除功能#20

Merged
aba2222 merged 2 commits into
aba2222:mainfrom
xiokuai:feature/comment-delete
Feb 23, 2026
Merged

feat: 添加评论删除功能#20
aba2222 merged 2 commits into
aba2222:mainfrom
xiokuai:feature/comment-delete

Conversation

@xiokuai
Copy link
Copy Markdown
Contributor

@xiokuai xiokuai commented Feb 20, 2026

Summary

  • 评论作者可以删除自己的评论
  • 删除前有浏览器确认弹窗,防止误操作
  • 仅评论作者可见删除按钮,服务端同样校验权限

Changes

  • forum/views.py: 新增 comment_delete_view,校验评论作者身份后删除
  • forum/urls.py: 新增 comments/<id>/delete/ 路由
  • forum/templates/forum/post_detail.html: 评论区添加删除按钮(仅作者可见)

Comment thread forum/templates/forum/post_detail.html Outdated
<span>
<small class="text-muted">{{ comment.created_at|date:"Y-m-d H:i" }}</small>
{% if comment.author == request.user %}
<form method="post" action="{% url 'comment_delete' comment_id=comment.id %}" class="d-inline ms-2" onsubmit="return confirm('确定删除这条评论吗?')">
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的弹窗确认过于简单了,最好有像删除用户或帖子一样的输入确认。弹出或跳转出一个确认框要求输入正确文本才可删除的更安全和风格统一。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用了个位数加法来进行验证并统一了样式

@aba2222
Copy link
Copy Markdown
Owner

aba2222 commented Feb 21, 2026

你能解决一下分支的冲突吗?

使用随机加法验证替代简单弹窗,风格与帖子删除页面统一。
解决分支冲突,合并楼层号功能。
@xiokuai xiokuai force-pushed the feature/comment-delete branch from 8873583 to 4e768ed Compare February 23, 2026 05:03
@aba2222 aba2222 merged commit 757bc52 into aba2222:main Feb 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants