您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
pip install django-pure-pagination
INSTALLED_APPS = [
'pure_pagination',
]
#引入
from pure_pagination import Paginator, EmptyPage, PageNotAnInteger
class UserHistoryView(LoginRequiredMixin,ListView):
'''登录日志'''
queryset = UserLog.objects.all().order_by('-login_time')
template_name = 'users/user_history.html'
# context_object_name = 'user_history'
def get_context_data(self, **kwargs):
#分页开始
try:
page = self.request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# 这里指从all中取10个出来,每页显示10个
p = Paginator(self.queryset, 10, request=self.request)
page_list = p.page(page)
print(page_list)
context = {
"platform_active": "active",
"user_log_active": "active",
#返回给模板
"page_list":page_list,
}
kwargs.update(context)
return super(UserHistoryView, self).get_context_data(**kwargs)
<div class="table-responsive">
<form id="del_form_asset_all" class="form-horizontal ">
<table class="table table-striped table-bordered table-hover dataTables-example">
<thead>
<tr>
<th>ID</th>
<th>用户</th>
<th>客户端</th>
<th>来源IP</th>
<th>城市</th>
<th>登录时间</th>
</tr>
</thead>
<tbody>
{% for user_history in page_list.object_list %}
<tr class="gradeA">
<td>{{ user_history.id }}</td>
<td>{{ user_history.username }}</td>
<td>{{ user_history.user_agent }}</td>
<td>{{ user_history.ip }}</td>
<td>{{ user_history.city }}</td>
<td>{{ user_history.login_time }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
#分页开始
<div>
<ul class="pagination pull-right">
{% if page_list.has_previous %}
<li class="long"><a
href="?{{ page_list.previous_page_number.querystring }}">上一页</a>
</li>
{% endif %}
{% for page in page_list.pages %}
{% if page %}
{% ifequal page page_list.number %}
<li class="active"><a href="?{{ page.querystring }}">{{ page }}</a>
</li>
{% else %}
<li><a href="?{{ page.querystring }}">{{ page }}</a>
{% endifequal %}
{% else %}
<li class="none"><a href="">...</a></li>
{% endif %}
{% endfor %}
{% if page_list.has_next %}
<li class="long"><a
href="?{{ page_list.next_page_number.querystring }}">下一页</a></li>
{% endif %}
</ul>
</div>
</div>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。