def update_comment(request): refer = request.META.get('HTTP_REFERER', reverse('article:home')) form = CommentForms(request.POST) data = {} if form.is_valid(): aid = request.POST.get('aid') print("aid=", aid) comment = Comment() # comment = Us comment.name = form.cleaned_data['name'] comment.email = form.cleaned_data['email'] comment.article = Article.objects.get(id=aid) comment.context = form.cleaned_data['context'] parent_id = form.cleaned_data['parent_id'] if parent_id != -1: comment.parent = Comment.objects.get(id=parent_id) comment.save() # 返回的参数 data['status'] = 'success' data['username'] = request.user.username data['comment_time'] = comment.created_time.strftime( '%Y-%m-%d %H-%M-%S') data['text'] = comment.context data['commnet_id'] = comment.id print(data) else: data['status'] = 'Error' data['message'] = list(form.errors.values())[0][0] # 以Json的形式返回数据 return JsonResponse(data)