Adjustment of pagination in django?

There is such code
def articles(request):
 all_articles = Article.objects.all()
try:
 page = request.GET.get('page')
except:
 page = 1
 paginator = Paginator(all_articles,1)
try:
 articless = paginator.page(page)
 except PageNotAnInteger:
 articless = paginator.page(1)
 except EmptyPage:
 articless = paginator.page(paginator.num_pages)
 return render_to_response('articles.html',{'articless':articless})

And this pattern
<nav class="text-center">
<ul class="pagination">
 {% if articless.has_previous %}
 the <li><a href="?page={{articless.previous_page_number}}">"</a></li>
 {% else %}
 <li class="disabled"><a href>"</a></li>
 {% endif %}
 {% for page in articless.paginator.page_range %}
 {% if page == articless.number %}
 <li class="active"><a>{{ page }}</a></li>
 {% else %}
 the <li><a href="?page={{ page }}">{{ page }}</a></li>
 {% endif %}
 {% endfor %}
 {% if articless.has_next %}
 the <li><a href="?page={{articless.next_page_number }}">"</a></li>
 {% else %}
 <li class="disabled"><a href>"</a></li>
 {% endif %}
</ul>
 </nav>

How can I implement a breakdown of the pages of the plan "1.. 5 6 7 ..10"? The standard way it turns out f67ababc06f9408697e671e811ea3248.png
July 12th 19 at 17:30
1 answer
July 12th 19 at 17:32
Solution
For example, a piece of my old code:
<div class="page-nav">
 {% if paginator.page.has_previous %}
 <!-- Pokazyvaem button with a link, if there is a previous page -->
 <a href="{% url 'newslines:show_page' paginator.page.previous_page_number %}">< Forward</a>
 {% else %}
 <!-- Show inactive button if the previous page there -->
 <span>< Forward</span>
 {% endif %}

 <!-- Added to the current page number -4 (i.e. subtract 4) -->
 {% if paginator.page.number|add:'-4' > 0 %} 
 <!-- If the current page is more than 4 pages to display the ellipsis -->
 <span class="ellipsis">...</span>
 {% endif %}

 {% if paginator.page.number|add:'-3' > 0 %}
 <!-- If current page is three more pages -->
 <a href="{% url 'newslines:show_page' paginator.page.number|add:'-3' %}">{{ paginator.page.number|add:'-3' }}</a>
 {% endif %}
 {% if paginator.page.number|add:'-2' > 0 %}
 <!-- If the current page there are two more pages -->
 <a href="{% url 'newslines:show_page' paginator.page.number|add:'-2' %}">{{ paginator.page.number|add:'-2' }}</a>
 {% endif %}
 {% if paginator.page.number|add:'-1' > 0 %}
 <!-- If the current page there is another page -->
 <a href="{% url 'newslines:show_page' paginator.page.number|add:'-1' %}">{{ paginator.page.number|add:'-1' }}</a>
 {% endif %}

 <!-- The current page number -->
 <span>{{ paginator.page.number }}</span>

 {% if paginator.page.number|add:'1' <= paginator.num_pages %}
 <!-- If after the current page there is another page -->
 <a href="{% url 'newslines:show_page' paginator.page.number|add:'1' %}">{{ paginator.page.number|add:'1' }}</a>
 {% endif %}
 {% if paginator.page.number|add:'2' <= paginator.num_pages %}
 <!-- If after the current page there are two more pages -->
 <a href="{% url 'newslines:show_page' paginator.page.number|add:'2' %}">{{ paginator.page.number|add:'2' }}</a>
 {% endif %}
 {% if paginator.page.number|add:'3' <= paginator.num_pages %}
 <!-- If after the current page has three more pages -->
 <a href="{% url 'newslines:show_page' paginator.page.number|add:'3' %}">{{ paginator.page.number|add:'3' }}</a>
 {% endif %}

 {% if paginator.page.number|add:'4' <= paginator.num_pages %}
 <!-- If after the current page are four more pages -->
 <span class="ellipsis">...</span>
 {% endif %} 

 {% if paginator.page.has_next %}
 <!-- Pokazyvaem button with a link, if there is a next page -->
 <a href="{% url 'newslines:show_page' paginator.page.next_page_number %}">Back ></a>
 {% else %}
 <!-- If there is no next page -->
 <span>Ago ></span>
 {% endif %}
</div>


It turns out that's the pagination ef086be9918f47099a2dc17857a32883.png
Add elements for the first and last pages are not so hard, if necessary.

Or you can use this recipe.
Did the tutorial - nothing happens. You can explain your code? In Django not so long ago. - gregory_Kovacek commented on July 12th 19 at 17:35
: added comments. - Rhiannon_Langworth commented on July 12th 19 at 17:38
: Thank you, it works. - gregory_Kovacek commented on July 12th 19 at 17:41
if you then specifically your example does not work
help - Parker10 commented on July 12th 19 at 17:44

Find more questions by tags Django