views.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:django-blog 作者: shawon922 项目源码 文件源码
def delete_comment(request, id=None):
    # if request.method == 'POST':
    # comment = get_object_or_404(Comment, id=id)
    try:
        comment = Comment.objects.get(id=id)
    except:
        raise Http404

    if comment.user != request.user:
        response = HttpResponse("You do not have permission to view this.")
        response.status_code = 403
        return response

    parent_url = comment.content_object.get_absolute_url()
    comment.delete()
    return HttpResponseRedirect(parent_url)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号