M
M
Mike2016-02-10 07:38:26
Django
Mike, 2016-02-10 07:38:26

How to split twenty blog posts into two pages in django?

I have twenty blog posts and they are all in a row, how do I make each page have 10 posts?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Kuts, 2016-02-10
@fox_12

Use Pagination and Common based views.
For example:
Specify in views.py:

...
from django.views.generic import ListView
...
class RecordsListView(ListView):
    template_name = 'record_list_view.html'
    model = Record
    paginate_by = 10

and in template 'record_list_view.html something like:
...
{% for record in object_list %}

    ...
{% endfor %}

    {% if is_paginated %}
        <div class="row">
            <div class="col-sm-4">
                <div class="dataTables_info" id="dynamic-table_info" role="status" aria-live="polite">
                    Показано с {{ page_obj.start_index }} по {{ page_obj.end_index }} из {{ page_obj.paginator.count }} результатов
                </div>
            </div>
            <div class="col-sm-2">
                <div class="dataTables_paginate paging_simple_numbers" id="dynamic-table_paginate">
                    <ul class="pagination">

                        {% if page_obj.has_previous %}
                        <li class="paginate_button previous" aria-controls="dynamic-table" tabindex="0">
                            <a href="{% url 'recordt_list'%}?page={{ page_obj.previous_page_number }}{{ search_data|set_search_data }}">Пред.</a>
                        </li>
                        {% else %}
                        <li class="paginate_button disabled previous" aria-controls="dynamic-table" tabindex="0">
                            <a href="{% url 'ticket_list'%}">Пред.</a>
                        </li>
                        {% endif %}

                        <li class="paginate_button active" aria-controls="dynamic-table" tabindex="0">
                            <a href="{% url record_list'%}?page={{page_obj.number}}{{ search_data|set_search_data }}">{{ page_obj.number }}</a>
                        </li>

                        {% if page_obj.has_next %}
                        <li class="paginate_button next" aria-controls="dynamic-table" tabindex="0">
                            <a href="{% url 'rtecord_list'%}?page={{ page_obj.next_page_number }}{{ search_data|set_search_data }}">След.</a>
                        </li>
                        {% else %}
                        <li class="paginate_button next disabled" aria-controls="dynamic-table" tabindex="0">
                            <a href="{% url 'record_list'%}?page={{ page_obj.paginator.num_pages }}">След.</a>
                        </li>
                        {% endif %}

                    </ul>
                </div>
            </div>
        </div>
    {% endif %}
...

V
Vladimir, 2016-02-10
@vintello

The author, dear users Denis Sh , Evgeny Borodenkov , Vladimir gave the right way and each according to his own understanding. but from your question it is not clear how you want to separate all this, why. in general, speaking the language of medicine, in order to make a diagnosis and give a prescription for treatment, you must actually at least understand what the patient is sick with. and your illness sounds like "here, doctor, my right hurts. give me a pill to fix everything"

D
Denis Sh, 2016-02-10
@Deq56

Paginator
djbook.ru/rel1.4/topics/pagination.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question