def article_detail(request, article_id): ''' 文章详情页 :param request: :return: 返回当前文章对象 ''' article_obj = models.Article.objects.get(id=article_id) # 调用构造树函数 comment_handler.build_tree(article_obj.comment_set.select_related()) return render(request, "bbs/article.html", { "article_obj": article_obj, "category_list": category_list, })
def get_comments(request, article_id): article_obj = models.Article.objects.get(id=article_id) comment_tree = comment_handler.build_tree( article_obj.comment_set.select_related()) tree_html = comment_handler.render_comment_tree(comment_tree) return HttpResponse(tree_html)
def article_detail(request, article_id): article_obj = models.Article.objects.get(id=article_id) comment_tree = comment_handler.build_tree( article_obj.my_comment.select_related()) return render(request, 'bbs/article_detail.html', { 'article_obj': article_obj, 'category_list': category_list })
def article_detail(request, article_id): article_obj = models.Article.objects.get(id=article_id) comment_tree = comment_handler.build_tree( article_obj.comment_set.select_related()) return render(request, "bbs/article_detail.html", { "article_obj": article_obj, "category_list": category_list })
def get_comments(request,article_id): article_obj = models.Article.objects.get(id=article_id) #通过文章id获取文章对象 comment_tree = comment_handler.build_tree(article_obj.comment_set.select_related()) #把文章对象给后端处理函数comment_handler.build_tree生成树 tree_html = comment_handler.render_comment(comment_tree) #把评论树对象给html渲染函数,因为前端不能处理递归的数据,所以在后端渲染好返回给前端 return HttpResponse(tree_html)
def get_comments(request, article_id): article_obj = models.Article.objects.filter(id=article_id)[ 0] #filter(id=1)[0] 等价于 get(id=1) ,filter返回的是对象列表,get返回的是对象 comment_related = list(article_obj.my_comment.select_related( )) #order_by('-id') id倒序排列 order_by('id')id正序排列,但倒序后子评论没了 print(comment_related) comment_obj = comment_handler.build_tree(comment_related) print(comment_obj) comment_tree = comment_handler.render_comment_tree(comment_obj) print(comment_tree) return HttpResponse(comment_tree)
def get_comments(request, article_id): ''' 获取文章评论 :param request: :return: ''' article_obj = models.Article.objects.get(id=article_id) comment_tree = comment_handler.build_tree( article_obj.comment_set.select_related()) # 手动将评论字典拼接评论成html代码 tree_html = comment_handler.render_comment_tree(comment_tree) return HttpResponse(tree_html)
def get_comments(request, article_id): """获取评论""" article_obj = models.Article.objects.get(id=article_id) comment_tree = comment_handler.build_tree(article_obj.comment_set.select_related().order_by('parent_comment', '-id')) tree_html = comment_handler.render_commnet_tree(comment_tree) return HttpResponse(tree_html)