【问题标题】:How to split template for the given link for pagination :如何为给定链接拆分模板以进行分页:
【发布时间】:2016-10-14 16:44:40
【问题描述】:

鉴于此link 用于 Django 中的推特式分页。我正在尝试在我的应用程序中实现相同的功能,但无法理解模板的拆分。我在这里给出了我想要应用分页的 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 %}

【问题讨论】:

    标签: django django-pagination


    【解决方案1】:

    在 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 %}
    

    【讨论】:

    • 试过这个。现在我正在显示我的前 10 个(共 13 个)对象,但是当我单击显示更多时,接下来的 3 个对象与前 3 个对象重叠
    • 由于在前 3 个对象之后获得了接下来的 3 个对象,因此分页效果很好。请添加/删除示例中的类属性以满足您的需要。与分页相关的是 load、paginate 和 show_more 模板标签。
    猜你喜欢
    • 2020-12-12
    • 2023-03-14
    • 2013-04-29
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    相关资源
    最近更新 更多