Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)