django的ajax对应前端的瀑布流方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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{
            width: 245px;
        }
        .c1 img{
            width: 245px;
            height: 200px;
        }
    </style>

    <div id="container" style="margin: 0 auto;width: 980px;" class="clearfix">

        <div style="width: 245px;float: left">

        </div>

        <div style="width: 245px;float: left">

        </div>

        <div style="width: 245px;float: left">


        </div>

        <div style="width: 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

 

以上是关于django的ajax对应前端的瀑布流方法的主要内容,如果未能解决你的问题,请参考以下文章

Django 之瀑布流实现

django模板中使用JQ代码实现瀑布流显示效果

django-jsonp 瀑布流 组合搜索 多级评论

Dreamweaver 怎么实现瀑布流

前端jQuery实现瀑布流

ajax抓取网站接口图片瀑布流笔记