zoukankan      html  css  js  c++  java
  • 添加子评论

    comment_list = []
    for comment in comments:
    for item in comment_list:
    if not hasattr(item, 'children_comment'):
    setattr(item, 'children_comment', [])
    if comment.pid == item:
    item.children_comment.append(comment)
    break
    if comment.pid is None:
    comment_list.append(comment)
    查看是不是有子评论,有的话就加到子评论列表里面
            if not hasattr(item, 'children_comment'):
    setattr(item, 'children_comment', [])
    判断item里面有没有children_comment的属性,没有的话,就给他加一个children_comment的属性,并初始化为[]
            if comment.pid == item:
    item.children_comment.append(comment)
    判断当前对象是不是父评论对象
    comment_form = CommentForm({'author': request.user.username,
    'email': request.user.email,
    'url': request.user.url,
    'article': id} if request.user.is_authenticated() else{'article': id})
    初始化Comment

    Form实例对象,如果user存在,因为使用了Django的表单验证,所以Django会把user对象传递到request当中,(我是这么理解的不知道对不对),然后就实例化了一个CommnetForm对象

     request.user.is_authenticated
    comment_form = CommentForm(request.POST)





  • 相关阅读:
    Less-21
    Less-22
    Less-21
    Less-20
    ssrf redis gopher
    Less19
    Less18
    Arm 系统查看、修改系统时间
    通过 grpc 请求标头发送自定义数据
    gRpc 空参数
  • 原文地址:https://www.cnblogs.com/wuqingzangyue/p/5749554.html
Copyright © 2011-2022 走看看