django+layui

权浩邈
2023-12-01
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>COM站群</title>
    {% load staticfiles %}
    <link rel="stylesheet" href="{% static "layui/css/layui.css" %}">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        {% include 'public/header.html' %}
        {% include 'public/left.html' %}
        <div class="layui-body">
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</body>
<script src="{% static "js/jquery.js" %}"></script>
<script src="{% static "layui/layui.all.js" %}"></script>
<script src="{% static 'js/crc32.js' %}"></script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑基本信息</a>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo',
            method: 'post',
            height: 590,
            url: '/url_list',
            page: true,
            cols: [[ //表头
                {type:'checkbox', fixed: 'left'},
                {field: 'index_url', title: 'URL',sort: true, fixed: 'left'},
                {fixed: 'right', title:"操作", width:200, align:'center', toolbar: '#barDemo'}
            ]]
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID:'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.alert('编辑行:<br>'+ JSON.stringify(data))
            }
        });
    });
</script>
</html>
def url_list(request):
    page = request.POST['page']
    limit = request.POST['limit']
    start = (int(page) - 1) * int(limit)
    end = int(page) * int(limit)
    urls = Urls.objects.filter(index_url__startswith="www.")
    count = len(urls)
    urls = Urls.objects.filter(index_url__startswith="www.")[start:end].values()
    urls = list(urls)
    for i, value in enumerate(urls):
       if urls[i]['status'] == "0":
 		urls[i]['status'] = "待发布"
       elif urls[i]['status'] == "1":
          	urls[i]['status'] = "<p style='color:green'>发布成功</p>"
       elif urls[i]['status'] == "3":
               urls[i]['status'] = "<p style='color:red'>发布失败</p>"
    data = {"code": 0, "msg": "", "count": count, "data": urls}
    return JsonResponse(data, safe=False)
#  in的用法
import json
#  json转数组
arr = json.loads(api_table_name)
urls = Webcf.objects.filter(api_table_name__in=arr)
 类似资料: