设为首页 加入收藏

TOP

开发一个博客园系统(五)
2017-12-24 06:07:03 】 浏览:1269
Tags:开发 一个 博客 系统
'我看是','parent_id':4}, {'id':6,'content':'鸡毛','parent_id':2}, {'id':7,'content':'你是没呀','parent_id':5}, {'id':8,'content':'惺惺惜惺惺想寻','parent_id':3}, ] msg_list_dict = {} for item in msg_list: item['child'] = []#每一行加一个空列表child,存放子数据 msg_list_dict[item['id']] = item#每个行加一个索引的序列改造成[1;{},2:{}] # #### msg_list_dict用于查找,msg_list result = [] for item in msg_list: pid = item['parent_id'] if pid:#如果有父id msg_list_dict[pid]['child'].append(item)#加到刚才的child列表中 else: result.append(item)#列表里都是第一级的评论 # ########################### 打印 ################### from utils.comment import comment_tree comment_str = comment_tree(result)#自定义把所有的评论一级一级递归的拨开,解析成HTML格式 多级评论
def comment_tree(comment_list):
    """

    :param result: [ {id,:child:[xxx]},{}]
    :return:
    """
    comment_str = "<div class='comment'>"
    for row in comment_list:
        tpl = "<div class='content'>%s</div>" %(row['content'])
        comment_str += tpl
        if row['child']:
            #
            child_str = comment_tree(row['child'])
            comment_str += child_str
    comment_str += "</div>"

    return comment_str
util.comment

  个人觉得也可以写成博客园的@的方式,@的回复可跨表取到。

{% for re in reply %}
    <div style="background-color: #e0e0e0">{{ re.comment__create_time }}&nbsp [发言人]{{ re.comment__user__username }}</div>
    {% if re.comment__reply__user__username %}
    <p>@{{ re.comment__reply__user__username }}</p>
        {% else %}
        <p></p>
    {% endif %}
<div style="width: 100%;border-bottom: #00b3ee 1px solid ;margin-top: 5px">  {{ re.comment__content }} </div>

{% endfor %}
数据可以后端跨表取

  点赞要给赞绑定点击事件,定义1为赞,0为踩,

onclick="updown(this,{{ content.nid }},1);//传给绑定事件触发的函数
        function updown(ths,nid,val){
            $.ajax({
                url: '/updown.html',
                data:{'val':val,'nid':nid,'csrfmiddlewaretoken':'{{ csrf_token }}'},
                type: "POST",
                dataType:'JSON',
                success:function(arg){
                    if(arg.status){
                        // 点赞成功刷新页面
                        location.reload();
                    }else{
                        alert(arg.msg)
                    }
                }
            })
        }
绑定事件

  后台管理可以使用xadmin来做,当然也可以写一个后台管理,我这个后台管理暂时使用管理员管理界面。

  xadmin使用方法

  这两天把后台搭起来再把源码上传。

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数据分析R&Python-Rpy2包环境配置 下一篇python3 爬虫---爬取糗事百科

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目