django自带分页(补)

注:只突出分页,其余功能可能不全

例:
views.py

from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

def index(request):
    article_list = models.Article.objects.all().order_by('-publish_date')
    paginator = Paginator(article_list, 3) # Show 25 contacts per page
    page = request.GET.get('page')
    try:
        articles = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        articles = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        articles = paginator.page(paginator.num_pages)

    return render(request,'index.html',{
        'articles': articles
    })

template

            {% for article in articles %}
                 
![](/static/{{ article.head_img }})

{{ article.title }}

{{ article.author.name }} {{ article.publish_date }}> 4 9
{{ article.summary }}
{% endfor %}

你可能感兴趣的:(django自带分页(补))