对于所有模板,所有django列表在我的模板中出现两次

时间:2017-08-01 16:19:24

标签: python ajax django linked-list

在我的django模板中,每当我在任何项目应用模板中执行for循环时,它都会显示整个页面enter image description here

这是我的 base.html

**{% load staticfiles %}
{% load crispy_forms_tags %}
<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="icon" type="png" sizes="192x192" href="{% static 'media/icon-0.png' %}">
         <title>Virgin city - {% block title %}{% endblock %}</title>

    <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.min.css' %}">
    <!-- Bootstrap theme -->
    <link rel="stylesheet" type="text/css" href="{% static 'static/css/bootstrap-theme.min.css' %}">
    <link rel="stylesheet" type="text/css" href="{% static 'static/css/theme.css' %}">
    <link rel="stylesheet" type="text/css" href="{% static 'static/css/main.css' %}">
    <link rel="stylesheet" type="text/css" href="{% static 'static/css/base.css' %}">
    <link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}">
    </head>
    <body>

    {% include 'navbar.html' %}

        <div id="content">
        {% if messages %}
            <ul class="messages">
                {% for message in messages %}
            <li class="{{ message.tags }}">
                {{ message|safe }}
            <a href="." class="close">✖</a>
            </li>
                {% endfor %}
            </ul>
        {% endif %}
            {% block content %}
            {% endblock %}
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src=" http://cdn.jsdelivr.net/jquery.cookie/1.4.1/jquery.cookie.min.js "></script>
        <script>
            var csrftoken = $.cookie('csrftoken');
            function csrfSafeMethod(method) {
            // these HTTP methods do not require CSRF protection
            return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
            }
            $.ajaxSetup({
            beforeSend: function(xhr, settings) {
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
            xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
            }
            });
        $(document).ready(function(){
            {% block domready %}
            {% endblock %}
        });
        </script>
    </body>
</html>**

这是我上面截图的 html 。当我滚动浏览页面以显示列表项时,我复制了用于加载列表的ajax。

提前致谢

这是ajax块 {%block domready%}

{% block domready %}
    var page = 1;
var empty_page = false;
var block_request = false;
$(window).scroll(function() {
var margin = $(document).height() - $(window).height() - 200;
if ($(window).scrollTop() > margin && empty_page == false &&
block_request == false) {
block_request = true;
page += 1;
$.get('?page=' + page, function(data) {
if(data == '') {
empty_page = true;
}
else {
block_request = false;
$('#image-list').append(data);
}
});
}
});
{% endblock %}}

0 个答案:

没有答案