zoukankan      html  css  js  c++  java
  • django的ajax对应前端的瀑布流方法

    html

    {% load xx %}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
        <div>
    
        </div>
        <style>
            .clearfix:after{
                content: '.';
                visibility: hidden;
                height: 0;
                clear: both;
                display: block;
            }
            .c1{
                 245px;
            }
            .c1 img{
                 245px;
                height: 200px;
            }
        </style>
    
        <div id="container" style="margin: 0 auto; 980px;" class="clearfix">
    
            <div style=" 245px;float: left">
    
            </div>
    
            <div style=" 245px;float: left">
    
            </div>
    
            <div style=" 245px;float: left">
    
    
            </div>
    
            <div style=" 245px;float: left">
    
    
            </div>
        </div>
    
        <script src="/static/js/jquery-2.1.4.min.js"></script>
        <script>
            $(function () {
                $.ajax({
                    url: '/student1/',
                    type: 'POST',
                    dataType: 'json',
                    success: function (arg) {
                        //arg = JSON.parse(arg);
                        // arg = JSON.stringify(arg)
                        $.each(arg, function (k,v) {
                            k = k + 1;
                            var div = document.createElement('div');
                            div.className = 'c1';
                            var img = document.createElement('img');
                            img.src = "/" + v.student__pic;
                            var p = document.createElement('p');
                            p.innerText =  v.letter_of_thanks;
                            div.appendChild(img);
                            div.appendChild(p);
                            if(k%4 == 1){
                                $('#container').children(':eq(0)').append(div);
                            }else if(k%4 == 2){
                                $('#container').children(':eq(1)').append(div);
                            }else if(k%4 == 3){
                                $('#container').children(':eq(2)').append(div);
                            }else if(k%4 == 0){
                                $('#container').children(':eq(3)').append(div);
                            }else{
    
                            }
                        })
                    }
                })
            })
        </script>
    </body>
    </html>
    html

    views

    def student1(request):
    
        if request.method == 'POST':
            detail_list = models.StudentDetail.objects.filter(student__status=1).values('letter_of_thanks', "student__name",
                                                                                        "student__salary",
                                                                                        'student__company', 'student__pic')
            detail_list = list(detail_list)
            return HttpResponse(json.dumps(detail_list))
        # student
        # studentDetail
        # detail_list = models.StudentDetail.objects.filter(student__status=1).values('letter_of_thanks',"student__name","student__salary",'student__company', 'student__pic')
        return render(request,'student1.html')
    views
  • 相关阅读:
    [转]拜占庭故障 & Paxos 算法
    如何让 YARN 支持 CNPM 的完整加速
    面试必问系列:悲观锁和乐观锁的那些事儿
    ajax下载文件的坑
    mac 装homebrew
    SLF4J报错问解决
    java追加文件
    CentOS 清理空间
    Dockerfile 通过 ARG 设置 ENV 无效的原因
    GoLang 中发送 email 邮件
  • 原文地址:https://www.cnblogs.com/renfanzi/p/5840164.html
Copyright © 2011-2022 走看看