“Pagination Django” Kode Jawaban

menangani pertanyaan di ListView Django

class ProfileList(ListView):
    template_name = 'your_template.html'
    model = Profile

    def get_queryset(self):
        query = self.request.GET.get('q')
        if query:
            object_list = self.model.objects.filter(name__icontains=query)
        else:
            object_list = self.model.objects.none()
        return object_list
TitanVentura006

template pagination django yang tepat

{% if is_paginated %}
    {% load proper_paginate %}
    {% load url_replace %}
    <ul class="pagination">
        {% if page_obj.number == 1 %}
            <li class="disabled"><span>⇤</span></li>
        {% else %}
            <li><a class="page-link" href="?{% url_replace request 'page' 1 %}">⇤</a></li>
        {% endif %}
        {% if page_obj.has_previous %}
            <li><a class="page-link" href="?{% url_replace request 'page' page_obj.previous_page_number %}">«</a></li>
        {% else %}
            <li class="disabled"><span>«</span></li>
        {% endif %}
        {% for i in paginator|proper_paginate:page_obj.number %}
            {% if page_obj.number == i %}
                <li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
            {% else %}
                <li><a class="page-link" href="?{% url_replace request 'page' i %}">{{ i }}</a></li>
            {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
            <li><a class="page-link" href="?{% url_replace request 'page' page_obj.next_page_number %}">»</a></li>
        {% else %}
            <li class="disabled"><span>»</span></li>
        {% endif %}
        {% if page_obj.number == paginator.num_pages %}
            <li class="disabled"><span>⇥</span></li>
        {% else %}
            <li><a class="page-link" href="?{% url_replace request 'page' paginator.num_pages %}">⇥</a></li>
        {% endif %}
    </ul>
{% endif %}
WarlordOmar

Pagination Django

{% if page_obj.has_previous %}
  <a href="?page={{ page_obj.previous_page_number }}">« Previous page</a>

  {% if page_obj.number > 3 %}
    <a href="?page=1">1</a>
    {% if page_obj.number > 4 %}
      <span>...</span>
    {% endif %}
  {% endif %}
{% endif %}

{% for num in page_obj.paginator.page_range %}
  {% if page_obj.number == num %}
    <a href="?page={{ num }}">{{ num }}</a>
  {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
    <a href="?page={{ num }}">{{ num }}</a>
  {% endif %}
{% endfor %}

{% if page_obj.has_next %}
  {% if page_obj.number < page_obj.paginator.num_pages|add:'-3' %}
    <span>...</span>
    <a href="?page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a>
  {% elif page_obj.number < page_obj.paginator.num_pages|add:'-2' %}
    <a href="?page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a>
  {% endif %}

  <a href="?page={{ page_obj.next_page_number }}">Next Page »</a>
{% endif %}
Adventurous Armadillo

Pagination Pencarian Django

from django.core.paginator import Paginator

def search(request):
    if 'results' in request.GET and request.GET['results']:
        page = request.GET.get('page', 1)

        results = request.GET['results']
        word = words.objects.filter(title__icontains = results).order_by('title')
        paginator = Paginator(word, 25) # Show 25 contacts per page
        word = paginator.page(page)
        return render_to_response('myapp/search.html',
                 {'word': word, 'query': results })
    else:
        return render(request, 'myapp/search.html')
Natthawut Ponkrut

Jawaban yang mirip dengan “Pagination Django”

Pertanyaan yang mirip dengan “Pagination Django”

Lebih banyak jawaban terkait untuk “Pagination Django” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya