如何分割给定链接的模板以进行分页:

时间:2016-10-12 11:45:49

标签: django django-pagination

鉴于这个link在Django中的twitter风格分页。我试图在我的应用中实现相同但不能理解模板的拆分。我在这里给出了我想要应用分页的HTML页面的代码。根据我的HTML代码,任何人都可以通过回答我应该在两个模板中写一个entry_index.html而另一个是entry_index_page.html(如链接中所提到的)来帮助我吗?

以下是我的应用分页的html页面代码:

{% extends 'talks/base.html' %}
{% block content  %}
<!-- .header-bottom-wrapper -->
<div class="header-bottom-wrapper">
<div class="container">
    <div class="row">
        <!-- Page Head -->
        <div class="page-head col-lg-12">
            <h2 class="page-title">Gallery</h2>
        </div>
        <!-- End Page Head -->
    </div>
    </div>
    </div><!-- End of .header-bottom-wrapper -->

 <!-- page-container -->
<div class="page-container container">

<!-- Gallery Filter -->

<div id="gallery-container">
    <div class="row gallery-4-columns isotope clearfix">


    {% for photo in pics %}
        <div class="gallery-item isotope-item issues  col-lg-3 col-md-3 col-sm-3 col-xs-6">
            <figure>
                <a class="zoom swipebox" href="{{photo.image.url}}" title="{{photo.title}}"></a>
                <div class="media_container"></div>
                <img src="{{photo.image.url}}" alt="{{photo.title}}" width="346px" height="200px">
            </figure>
        </div>
    {% endfor %}
    </div>

</div>

</div><!-- End of .page-container -->

{% endblock %}

1 个答案:

答案 0 :(得分:0)

在entry_index.html中:

{% extends 'talks/base.html' %}
{% block content  %}
<!-- .header-bottom-wrapper -->
<div class="header-bottom-wrapper">
<div class="container">
    <div class="row">
    <!-- Page Head -->
    <div class="page-head col-lg-12">
        <h2 class="page-title">Gallery</h2>
    </div>
    <!-- End Page Head -->
</div>
</div>
</div><!-- End of .header-bottom-wrapper -->

<!-- page-container -->
<div class="page-container container">

<!-- Gallery Filter -->

<div id="gallery-container">
    <div class="row gallery-4-columns isotope clearfix">

{%include page_template %}

</div>

你看我排除了for循环,我用

替换了它
{%include page_template %}

将for循环放入entry_index_page.html。 不要忘记像这里定义page_template变量: https://django-endless-pagination.readthedocs.io/en/latest/twitter_pagination.html#split-the-template

这是我第一次测试django-endless-pagination时的尝试,它是一个简单的显示照片列表,带有“显示更多”按钮:

{%  load el_pagination_tags %}
{% paginate photos %}
   {% for photo in photos %}
       <div class="well col-xs-12 col-md-8 col-md-offset-2">
            <div class="row">{{ forloop.counter }}</div>
            <div class="row">{{ photo.description }}</div>
            <div class="row">
                <div class="col-md-4">
                    <div class="thumbnail">
                        <img src="{{ photo.image.url }}" class="img-responsive">
                    </div>
                </div>
            </div>

       </div>

    {% endfor %}
{% show_more %}