标签:none install active val 首页 django color getattr request
django 分页例子python3.6 -m pip install django-pure-pagination==0.3.0
settings.py
INSTALLED_APPS = [
‘pure_pagination‘,
]
PAGINATION_SETTINGS = {
‘PAGE_RANGE_DISPLAYED‘: 3,
‘MARGIN_PAGES_DISPLAYED‘: 2,
‘SHOW_FIRST_PAGE_WHEN_INVALID‘: True,
}
DISPLAY_PER_PAGE = 15
from pure_pagination import PageNotAnInteger
from pure_pagination import Paginator
try:
page = self.request.GET.get(‘page‘, 1)
except PageNotAnInteger_He as e:
page = 1
p = Paginator_He(self.queryset, getattr(settings, ‘DISPLAY_PER_PAGE‘), request=self.request)
asset_list = p.page(page)
context = {
"ecs_list": asset_list,
}
<div style="text-align:center;">
<nav class="pagination">
<li><a href="{% url "asset:ecs_list" %}?page=1">首页 </a></li>
{% if ecs_list.has_previous %}
<li class="long"><a
href="?{{ ecs_list.previous_page_number.querystring }}">上一页</a>
</li>
{% endif %}
{% for page in ecs_list.pages %}
{% if page %}
{% ifequal page ecs_list.number %}
<li class="active"><a href="?{{ page.querystring }}">{{ page }}</a>
</li>
{% else %}
<li><a href="?{{ page.querystring }}" class="page">{{ page }}</a>
</li>
{% endifequal %}
{% else %}
<li class="none"><a href="">...</a></li>
{% endif %}
{% endfor %}
{% if ecs_list.has_next %}
<li class="long"><a
href="?{{ ecs_list.next_page_number.querystring }}">下一页</a>
</li>
{% endif %}
<li>
<a href="{% url "asset:ecs_list" %}?page={{ ecs_list.paginator.num_pages }}">尾页 </a>
</li>
<li><span
style="color: #0a0a0a">总: ?{{ ecs_list.paginator.num_pages }} 页</span>
</li>
<li><span
style="color: #0a0a0a"> ECS数量: {{ ecs_count }}</span>
</li>
</nav>
</div>
标签:none install active val 首页 django color getattr request
原文地址:http://blog.51cto.com/hequan/2316259