查看“蓝鲸Django: 删除及回复评论功能的实现”的源代码
←
蓝鲸Django: 删除及回复评论功能的实现
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==后台删除功能的实现== a)View 中编写删除函数: <nowiki>@login_required def delete_comment(request): comment_id = request.POST.get("comment_id") Reply.objects.filter(id=comment_id).delete() return JsonResponse({"result":True})</nowiki> b) urls.py: <nowiki> 。。。 from moments.views import like,comment,delete_comment urlpatterns = [ 。。。 path('comment/delete',delete_comment), ] </nowiki> ==前端删除功能的实现== ===编写删除确认弹窗=== 注意整个modal 为了使用方便,加个id号:id="deleteConfirm" <nowiki> <!-- Modal --> <div class="modal fade" id="deleteConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">删除确认</h4> </div> <div class="modal-body"> <textarea class="form-control" rows="5" id="text"> </textarea> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">取消</button> <button type="button" class="btn btn-primary" onclick="comment()">删除</button> </div> </div> </div> </div></nowiki> ===编写delete_or_comment 函数=== 并绑定到comment 的<nowiki><p></nowiki>标签: [[文件:bd20-5-59.png|600px]] <nowiki> function delete_or_comment(comment_id,user,comment_user,status_id) { if (user === comment_user) { $("#deleteConfirm").modal() $("#deleteConfirm").attr("comment_id",comment_id) }else { show_dialog(status_id) $("#myModal").attr("comment_at",comment_user) $("#myModal").find("textarea").attr("placeholder","@"+comment_user) } }</nowiki> <nowiki> {% for comment in status.comments %} <p style="font-size:30px" onclick="delete_or_comment('{{ comment.id }}','{{user }}','{{ comment.author }}', '{{ status.id}}')"> {{ comment.author }} {% if comment.at_person %}@{{ comment.at_person }} {% endif %}: {{ comment.text }} </p> {% endfor %}</nowiki> ===效果图=== 点击自己的评论时 [[文件:bd20-5-60.png]] 点击别人的评论时: [[文件:bd20-5-61.png]]
返回至
蓝鲸Django: 删除及回复评论功能的实现
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息