擅长:python、mysql、java
<p>你已经有了<code>{{ forloop.counter }}</code>在那里,你可以用它来限制到5。</p>
<pre><code> {% for l in Items.paginator.page_range %}
{% if forloop.counter < 5 %}
<li><a href="?page={{forloop.counter}}">{{forloop.counter}}</a></li>
{% endif %}
{% endfor %}
</code></pre>
<p>这是另一个解决方案,如果您感兴趣,它可能会给您更多的选择:<a href="https://stackoverflow.com/questions/5709468/django-pagination-display-issue-all-the-page-numbers-show-up">Django Pagination Display Issue: all the page numbers show up</a>。</p>
<p>最后,这里有一个非常好的教程,介绍如何加快django提供的现成分页:<a href="https://simpleisbetterthancomplex.com/tutorial/2016/08/03/how-to-paginate-with-django.html" rel="nofollow noreferrer">https://simpleisbetterthancomplex.com/tutorial/2016/08/03/how-to-paginate-with-django.html</a>。</p>